diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-06-08 11:28:14 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-06-08 11:28:58 +0200 |
commit | 234a4f63a6cfd1b942507b19af6d457f66972290 (patch) | |
tree | bc47ad8443cf8d5ce45d0f006cc40621e86ae50c /README.md | |
parent | 856a0c05fbbde4363634e7f8d5de7ed66d0e0cdc (diff) |
lib: implement b64enc() and b64dec() functions
The new functions allow encoding and decoding base64 values respectively.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -1226,3 +1226,31 @@ max("1", "abc"); // "abc" max("def", "abc", "ghi"); // "ghi" max(true, false); // true ``` + +#### 6.62. `b64dec(str)` + +Decodes the given base64 encoded string and returns the decoded result, any +whitespace in the input string is ignored. + +If non-whitespace, non-base64 characters are encountered, if invalid padding +or trailing garbage is found, the function returns `null`. + +If a non-string argument is given, the function returns `null`. + +```javascript +b64dec("VGhpcyBpcyBhIHRlc3Q="); // "This is a test" +b64dec(123); // null +b64dec("XXX"); // null +``` + +#### 6.63. `b64enc(str)` + +Encodes the given string into base64 and returns the resulting encoded +string. + +If a non-string argument is given, the function returns `null`. + +```javascript +b64enc("This is a test"); // "VGhpcyBpcyBhIHRlc3Q=" +b64enc(123); // null +``` |