Modules@robinpath/encode
encode

@robinpath/encode

0.1.1Node.jsPublic

Encoding and decoding conversions: Base64, Base32, hex, URL encoding, HTML entities, binary, ROT13, percent-encoding, and more

Encode

Encoding and decoding conversions: Base64, Base32, hex, URL encoding, HTML entities, binary, ROT13, percent-encoding, and more

Package: @robinpath/encode | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the encode module when you need to:

  • Encode a string or buffer to Base64 -- Use encode.base64Encode to perform this operation
  • Decode a Base64-encoded string -- Use encode.base64Decode to perform this operation
  • Encode a string to URL-safe Base64 (no padding, +/ replaced with -_) -- Use encode.base64UrlEncode to perform this operation
  • Decode a URL-safe Base64 string -- Use encode.base64UrlDecode to perform this operation
  • Encode a string to hexadecimal representation -- Use encode.hexEncode to perform this operation

Quick Reference

FunctionDescriptionReturns
base64EncodeEncode a string or buffer to Base64object
base64DecodeDecode a Base64-encoded stringobject
base64UrlEncodeEncode a string to URL-safe Base64 (no padding, +/ replaced with -_)object
base64UrlDecodeDecode a URL-safe Base64 stringobject
hexEncodeEncode a string to hexadecimal representationobject
hexDecodeDecode a hexadecimal string back to UTF-8object
base32EncodeEncode a string to Base32 (RFC 4648)object
base32DecodeDecode a Base32-encoded stringobject
urlEncodeEncode a string using encodeURIComponentobject
urlDecodeDecode a URL-encoded string using decodeURIComponentobject
htmlEncodeEncode HTML special characters into entitiesobject
htmlDecodeDecode HTML entities back to charactersobject
utf8EncodeEncode a string to an array of UTF-8 byte valuesobject
utf8DecodeDecode an array of UTF-8 byte values back to a stringobject
binaryEncodeEncode a string to its binary (0s and 1s) representationobject
binaryDecodeDecode a binary (0s and 1s) string back to textobject
asciiToCharConvert an ASCII code to its characterobject
charToAsciiConvert a character to its ASCII codeobject
rot13Apply ROT13 substitution cipher to a stringobject
percentEncodePercent-encode every byte of a string (e.g. 'A' becomes '%41')object
percentDecodeDecode a percent-encoded stringobject

Functions

base64Encode

Encode a string or buffer to Base64

Module: encode | Returns: object -- API response.

encode.base64Encode
ParameterTypeRequiredDescription
inputstringYesThe data to encode

base64Decode

Decode a Base64-encoded string

Module: encode | Returns: object -- API response.

encode.base64Decode
ParameterTypeRequiredDescription
inputstringYesThe Base64 string to decode

base64UrlEncode

Encode a string to URL-safe Base64 (no padding, +/ replaced with -_)

Module: encode | Returns: object -- API response.

encode.base64UrlEncode
ParameterTypeRequiredDescription
inputstringYesThe data to encode

base64UrlDecode

Decode a URL-safe Base64 string

Module: encode | Returns: object -- API response.

encode.base64UrlDecode
ParameterTypeRequiredDescription
inputstringYesThe URL-safe Base64 string to decode

hexEncode

Encode a string to hexadecimal representation

Module: encode | Returns: object -- API response.

encode.hexEncode
ParameterTypeRequiredDescription
inputstringYesThe data to encode

hexDecode

Decode a hexadecimal string back to UTF-8

Module: encode | Returns: object -- API response.

encode.hexDecode
ParameterTypeRequiredDescription
inputstringYesThe hex string to decode

base32Encode

Encode a string to Base32 (RFC 4648)

Module: encode | Returns: object -- API response.

encode.base32Encode
ParameterTypeRequiredDescription
inputstringYesThe data to encode

base32Decode

Decode a Base32-encoded string

Module: encode | Returns: object -- API response.

encode.base32Decode
ParameterTypeRequiredDescription
inputstringYesThe Base32 string to decode

urlEncode

Encode a string using encodeURIComponent

Module: encode | Returns: object -- API response.

encode.urlEncode
ParameterTypeRequiredDescription
inputstringYesThe string to URL-encode

urlDecode

Decode a URL-encoded string using decodeURIComponent

Module: encode | Returns: object -- API response.

encode.urlDecode
ParameterTypeRequiredDescription
inputstringYesThe URL-encoded string to decode

htmlEncode

Encode HTML special characters into entities

Module: encode | Returns: object -- API response.

encode.htmlEncode
ParameterTypeRequiredDescription
inputstringYesThe string to encode

htmlDecode

Decode HTML entities back to characters

Module: encode | Returns: object -- API response.

encode.htmlDecode
ParameterTypeRequiredDescription
inputstringYesThe HTML-encoded string to decode

utf8Encode

Encode a string to an array of UTF-8 byte values

Module: encode | Returns: object -- API response.

encode.utf8Encode
ParameterTypeRequiredDescription
inputstringYesThe string to encode

utf8Decode

Decode an array of UTF-8 byte values back to a string

Module: encode | Returns: object -- API response.

encode.utf8Decode
ParameterTypeRequiredDescription
inputarrayYesArray of byte values

binaryEncode

Encode a string to its binary (0s and 1s) representation

Module: encode | Returns: object -- API response.

encode.binaryEncode
ParameterTypeRequiredDescription
inputstringYesThe string to encode
separatorstringNoSeparator between bytes (default: ' ')

binaryDecode

Decode a binary (0s and 1s) string back to text

Module: encode | Returns: object -- API response.

encode.binaryDecode
ParameterTypeRequiredDescription
inputstringYesThe binary string to decode

asciiToChar

Convert an ASCII code to its character

Module: encode | Returns: object -- API response.

encode.asciiToChar
ParameterTypeRequiredDescription
codenumberYesASCII code (0-127)

charToAscii

Convert a character to its ASCII code

Module: encode | Returns: object -- API response.

encode.charToAscii
ParameterTypeRequiredDescription
charstringYesA single character

rot13

Apply ROT13 substitution cipher to a string

Module: encode | Returns: object -- API response.

encode.rot13
ParameterTypeRequiredDescription
inputstringYesThe string to transform

percentEncode

Percent-encode every byte of a string (e.g. 'A' becomes '%41')

Module: encode | Returns: object -- API response.

encode.percentEncode
ParameterTypeRequiredDescription
inputstringYesThe string to encode

percentDecode

Decode a percent-encoded string

Module: encode | Returns: object -- API response.

encode.percentDecode
ParameterTypeRequiredDescription
inputstringYesThe percent-encoded string to decode

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Base64 encode and validate result"
do
  set $result as encode.base64Encode
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Encode workflow

Chain multiple encode operations together.

@desc "Base64 encode, base64 decode, and more"
do
  set $r_base64Encode as encode.base64Encode
  set $r_base64Decode as encode.base64Decode
  set $r_base64UrlEncode as encode.base64UrlEncode
  print "All operations complete"
enddo

2. Safe base64Encode with validation

Check results before proceeding.

@desc "Base64 encode and validate result"
do
  set $result as encode.base64Encode
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/encode

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size5.4 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Category

utilities