Constructor
# new TokenList(init)
Name | Type | Description |
---|---|---|
init |
array | string | iteratable |
- Since:
- 1.2.0
- Copyright:
- schukai GmbH
Methods
# add(value) → {TokenList}
add tokens
new TokenList().add("abc xyz").toString(); // ↦ "abc xyz"
new TokenList().add(["abc","xyz"]).toString(); // ↦ "abc xyz"
new TokenList().add(undefined); // ↦ add nothing
Name | Type | Description |
---|---|---|
value |
array | string | iteratable |
-
unsupported value
- Type
- TypeError
- Type
- TokenList
# clear() → {TokenList}
remove all tokens
- Type
- TokenList
# contains(value) → {boolean}
Returns true if it contains token, otherwise false
new TokenList("start middle end").contains('start')); // ↦ true
new TokenList("start middle end").contains('end')); // ↦ true
new TokenList("start middle end").contains('xyz')); // ↦ false
new TokenList("start middle end").contains(['end','start','middle'])); // ↦ true
new TokenList("start middle end").contains(['end','start','xyz'])); // ↦ false
Name | Type | Description |
---|---|---|
value |
array | string | iteratable |
- Type
- boolean
# entries() → {array}
returns an array with all tokens
- Type
- array
# forEach(callback) → {TokenList}
executes the provided function with each value of the set
Name | Type | Description |
---|---|---|
callback |
function |
- Type
- TokenList
# getIterator() → {Symbol.iterator}
Iterator protocol
- Type
- Symbol.iterator
# remove(value) → {TokenList}
Removes token
new TokenList("abc xyz").remove("xyz").toString(); // ↦ "abc"
new TokenList("abc xyz").remove(["xyz"]).toString(); // ↦ "abc"
new TokenList("abc xyz").remove(undefined); // ↦ remove nothing
Name | Type | Description |
---|---|---|
value |
array | string | iteratable |
-
unsupported value
- Type
- TypeError
- Type
- TokenList
# replace(token, newToken) → {TokenList}
this method replaces a token with a new token.
if the passed token exists, it is replaced with newToken and TokenList is returned. if the token does not exist, newToken is not set and TokenList is returned.
Name | Type | Description |
---|---|---|
token |
string | |
newToken |
string |
- Type
- TokenList
# Symbol.iterator() → {Object}
Iterator
- Type
- Object
# toggle(value) → {boolean}
Removes token from string. If token doesn't exist it's added.
new TokenList("abc def ghi").toggle("def xyz").toString(); // ↦ "abc ghi xyz"
new TokenList("abc def ghi").toggle(["abc","xyz"]).toString(); // ↦ "def ghi xyz"
new TokenList().toggle(undefined); // ↦ nothing
Name | Type | Description |
---|---|---|
value |
array | string | iteratable |
-
unsupported value
- Type
- TypeError
- Type
- boolean
# toString() → {string}
returns the individual tokens separated by a blank character
- Type
- string