Constructor
new EncodeSet(chars)
Parameters:
Name | Type | Description |
---|---|---|
chars |
CharSet | Character set to encode |
- Source:
Methods
(static) extend(encodeSet, chars) → {EncodeSet}
Creates a new EncodeSet by extending the input EncodeSet with additional characters.
Parameters:
Name | Type | Description |
---|---|---|
encodeSet |
EncodeSet | Instance of EncodeSet |
chars |
CharSet | Character set to encode |
- Source:
Throws:
-
Argument
encodeSet
must be of type EncodeSet - Type
- TypeError
Returns:
Copy of given encodeSet
with extended chars
- Type
- EncodeSet
Example
var fooEncodeSet = new EncodeSet(['f', 'o'])
var foobarEncodeSet = EncodeSet.extend(fooEncodeSet, new Set(['b', 'a', 'r']))
(static) isEncodeSet(value) → {Boolean}
Determines whether the input value is an EncodeSet or not.
Parameters:
Name | Type | Description |
---|---|---|
value |
* | The value to be tested |
- Source:
Returns:
true if the given value is an EncodeSet; otherwise, false
- Type
- Boolean
Example
// returns true
EncodeSet.isEncodeSet(new EncodeSet([40, 41]))
// returns false
EncodeSet.isEncodeSet(new Set([28, 05]))
add(char) → {EncodeSet}
Appends a new character to the EncodeSet.
Parameters:
Name | Type | Description |
---|---|---|
char |
Char | Character or character code |
- Source:
Returns:
Current EncodeSet
- Type
- EncodeSet
Example
var xyzEncodeSet = new EncodeSet(['x', 'y', 'z'])
xyzEncodeSet
.add('X')
.add(89) // Y
.add(0x5a) // Z
clone() → {EncodeSet}
Creates a copy of the current EncodeSet.
- Source:
Returns:
New EncodeSet instance
- Type
- EncodeSet
Example
var set1 = new EncodeSet(['<', '>'])
var set1Copy = set1.clone().add('=')
has(code) → {Boolean}
Returns a boolean asserting whether the given char code will be encoded in the EncodeSet or not.
Parameters:
Name | Type | Description |
---|---|---|
code |
Number | Character code |
- Source:
Returns:
Returns true if the character with the specified char code exists in the EncodeSet; otherwise false
- Type
- Boolean
Example
var tildeEncodeSet = new EncodeSet(['~'])
// returns true
tildeEncodeSet.has('~'.charCodeAt(0))
// returns false
tildeEncodeSet.has(65) // A
// returns true
tildeEncodeSet.has(31) // \u001f (control character)
seal() → {EncodeSet}
Seals the current EncodeSet to prevent new characters being added to it.
- Source:
Returns:
Current EncodeSet
- Type
- EncodeSet
Example
var set = new EncodeSet()
set.add(95)
set.has(95) // returns true
set.seal()
set.add(100)
set.has(100) // returns false