codecs
codecs extends the String class to add encoding/decoding functionality.methods
- listEncoders()
lists all encoder names usable with String.encode(...).
return value:
An array of encoder names. - listDecoders()
lists all encoder names usable with String.decode(...).
return value:
An array of decoder names.
instance methods of String
- encode(codec)
Encodes a string using the specified codec.
parameters:- codec The name of the codec to use.
A new string encoded using the codec. - decode(codec)
Decodes a string using the specified codec.
parameters:- codec The name of the codec to use.
A new string decoded using the codec.
codecs
There are currently 2 codecs available:- base64
Encodes/decodes a string from and to Base64 encoded strings.
- uri
Uses encodeURI/decodeURI to encode/decode strings.
To add your own codec simply extend the String class with a method "decode_CodecName" and "encode_CodecName"
where CodecName is the name of your codec.
calling "someString".encode(yourCodecName) will call that codec method and pass all additional parameters passed to encode/decode to that method.