Constructor
new TokenList(init)
- Source:
- Since:
- 1.2.0
- Copyright:
- schukai GmbH
Parameters:
Name | Type | Description |
---|---|---|
init |
array | string | iteratable |
Methods
add(value) → {TokenList}
- Source:
add tokens
new TokenList().add("abc xyz").toString(); // ↦ "abc xyz"
new TokenList().add(["abc","xyz"]).toString(); // ↦ "abc xyz"
new TokenList().add(undefined); // ↦ add nothing
Parameters:
Name | Type | Description |
---|---|---|
value |
array | string | iteratable |
Throws:
-
unsupported value
- Type
- TypeError
Returns:
- Type
- TokenList
clear() → {TokenList}
- Source:
remove all tokens
Returns:
- Type
- TokenList
contains(value) → {boolean}
- Source:
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
Parameters:
Name | Type | Description |
---|---|---|
value |
array | string | iteratable |
Returns:
- Type
- boolean
entries() → {array}
- Source:
returns an array with all tokens
Returns:
- Type
- array
forEach(callback) → {TokenList}
- Source:
executes the provided function with each value of the set
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
Returns:
- Type
- TokenList
getIterator() → {Symbol.iterator}
- Source:
Iterator protocol
Returns:
- Type
- Symbol.iterator
remove(value) → {TokenList}
- Source:
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
Parameters:
Name | Type | Description |
---|---|---|
value |
array | string | iteratable |
Throws:
-
unsupported value
- Type
- TypeError
Returns:
- Type
- TokenList
replace(token, newToken) → {TokenList}
- Source:
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.
Parameters:
Name | Type | Description |
---|---|---|
token |
string | |
newToken |
string |
Returns:
- Type
- TokenList
Symbol.iterator() → {Object}
- Source:
Iterator
Returns:
- Type
- Object
toggle(value) → {boolean}
- Source:
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
Parameters:
Name | Type | Description |
---|---|---|
value |
array | string | iteratable |
Throws:
-
unsupported value
- Type
- TypeError
Returns:
- Type
- boolean
toString() → {string}
- Source:
returns the individual tokens separated by a blank character
Returns:
- Type
- string