Constructor
new TokenList(init)
Name | Type | Description |
---|---|---|
init | array | |
- Since
- 1.2.0
- Copyright
- schukai GmbH
- License
- AGPLv3
import {TokenList} from '@schukai/monster/source/types/tokenlist.mjs';
typeof new TokenList("myclass row")[Symbol.iterator];
// ↦ "function"
Methods
Symbol.iterator() → {Object}
Iterator
.Iterator
- Type:
- Object
add(value) → {TokenList}
Add tokens
.Add tokens
Name | Type | Description |
---|---|---|
value | array | |
unsupported value
- Type
- TypeError
- Type:
- TokenList
import {TokenList} from '@schukai/monster/source/types/tokenlist.mjs';
new TokenList().add("abc xyz").toString(); // ↦ "abc xyz"
new TokenList().add(["abc", "xyz"]).toString(); // ↦ "abc xyz"
new TokenList().add(undefined); // ↦ add nothing
clear() → {TokenList}
remove all tokens
.remove all tokens
- Type:
- TokenList
contains(value) → {boolean}
Returns true if it contains token, otherwise false
.Returns true if it contains token, otherwise false
Name | Type | Description |
---|---|---|
value | array | |
- Type:
- boolean
import {TokenList} from '@schukai/monster/source/types/tokenlist.mjs';
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
entries() → {array}
returns an array with all tokens
.returns an array with all tokens
- Type:
- array
forEach(callback) → {TokenList}
executes the provided function with each value of the set
.executes the provided function with each value of the set
Name | Type | Description |
---|---|---|
callback | function |
- Type:
- TokenList
getIterator() → {Symbol.iterator}
Iterator protocol
.Iterator protocol
- Type:
- Symbol.
iterator
remove(value) → {TokenList}
Removes token
.Removes token
Name | Type | Description |
---|---|---|
value | array | |
unsupported value
- Type
- TypeError
- Type:
- TokenList
import {TokenList} from '@schukai/monster/source/types/tokenlist.mjs';
new TokenList("abc xyz").remove("xyz").toString(); // ↦ "abc"
new TokenList("abc xyz").remove(["xyz"]).toString(); // ↦ "abc"
new TokenList("abc xyz").remove(undefined); // ↦ remove nothing
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
toString() → {string}
returns the individual tokens separated by a blank character
.returns the individual tokens separated by a blank character
- Type:
- string
toggle(value) → {boolean}
Removes token from string. If token doesn't exist it's added.
Name | Type | Description |
---|---|---|
value | array | |
unsupported value
- Type
- TypeError
- Type:
- boolean
import {TokenList} from '@schukai/monster/source/types/tokenlist.mjs';
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