new Listing(list)
Create Listing instance
Parameters:
Name | Type | Description |
---|---|---|
list |
string | = '' |
Members
delimiter
Get list delimiter. Returns "," as default delimiter.
length
Get list length
Methods
(static) arrayToList(array, delimiter) → {Listing}
Create new Listing instance from array
Parameters:
Name | Type | Default | Description |
---|---|---|---|
array |
Array.<string> | Array.<number> | ||
delimiter |
string | , | = ',' |
Returns:
new instance
- Type
- Listing
(static) isValidDelimiter(delimiter) → {boolean}
Check if the given delimiter is valid
Parameters:
Name | Type | Description |
---|---|---|
delimiter |
string |
Returns:
- Type
- boolean
append(item)
Append new item to list
Parameters:
Name | Type | Description |
---|---|---|
item |
string | number |
clear()
Clear list
concat(list)
Concat list with another given one.
Parameters:
Name | Type | Description |
---|---|---|
list |
Listing |
contains(substring) → {number}
Check if a list item contains a given substring and return its position (case-sensitive).
Return -1 otherwise.
Parameters:
Name | Type | Description |
---|---|---|
substring |
string |
Returns:
position
- Type
- number
containsNoCase(substring) → {number}
Check if a list item contains a certain substring and return its position (case-insensitive).
Return -1 otherwise.
Parameters:
Name | Type | Description |
---|---|---|
substring |
string |
Returns:
position
- Type
- number
deleteAt(position) → {string}
Delete a list item at a given position and return it.
Parameters:
Name | Type | Description |
---|---|---|
position |
number |
Returns:
deleted item
- Type
- string
each(callbackFn)
Iterate list and call a given callback function for each item.
Parameters:
Name | Type | Description |
---|---|---|
callbackFn |
function | callback function |
eachParsed(callbackFn)
Iterate list and call a given callback function for each item parsed as number.
Parameters:
Name | Type | Description |
---|---|---|
callbackFn |
function | callback function |
equals(list) → {boolean}
Check for equality with given list
Parameters:
Name | Type | Description |
---|---|---|
list |
Listing |
Returns:
- Type
- boolean
every(compareFn) → {boolean}
Determines whether all list elements satisfy the specified test.
Parameters:
Name | Type | Description |
---|---|---|
compareFn |
function | compare function |
Returns:
- Type
- boolean
filter(callbackFn) → {Listing}
Return the items that meet the condition specified in a callback function.
Parameters:
Name | Type | Description |
---|---|---|
callbackFn |
function | filter function |
Returns:
filtered list
- Type
- Listing
find(item) → {boolean}
Check if th list includes a given item (case-sensitive).
Parameters:
Name | Type | Description |
---|---|---|
item |
string |
Returns:
- Type
- boolean
findNoCase(item) → {boolean}
Check if the list includes a given item (case-insensitive).
Parameters:
Name | Type | Description |
---|---|---|
item |
string |
Returns:
- Type
- boolean
first() → {string|undefined}
Get the first list item.
Returns:
first item
- Type
- string | undefined
getAt(position) → {string|undefined}
Get the list item at a given position.
Use negative position to start from the list end.
Parameters:
Name | Type | Description |
---|---|---|
position |
number |
Returns:
item
- Type
- string | undefined
getDuplicates() → {Listing}
Return new listing instance of duplicated list items.
Returns:
duplicated items
- Type
- Listing
indexOf(item) → {number}
Get position in list of a given item.
Parameters:
Name | Type | Description |
---|---|---|
item |
string |
Returns:
position
- Type
- number
insertAt(position, item)
Insert item at given position.
Parameters:
Name | Type | Description |
---|---|---|
position |
number | |
item |
string |
isEmpty() → {boolean}
Returns true if the list is empty or otherwise.
Returns:
- Type
- boolean
last() → {string|undefined}
Get last list item.
Returns:
last item
- Type
- string | undefined
map(callbackFn)
Call a defined callback function on each item, and return a list that contains the results.
Parameters:
Name | Type | Description |
---|---|---|
callbackFn |
function | map function |
merge(list)
Merge list and skip duplicated values.
Parameters:
Name | Type | Description |
---|---|---|
list |
Listing |
prepend(item)
Prepend an item to the list.
Parameters:
Name | Type | Description |
---|---|---|
item |
string | number |
qualify(item)
Add an item at the start and end of the list.
Parameters:
Name | Type | Description |
---|---|---|
item |
string | number |
removeDuplicates()
Remove duplicated list items.
rest() → {Listing}
Get the list without the first item.
Returns:
- Type
- Listing
reverse()
Reverse list items in place.
setAt(position, value)
Set a list item to a value at a given position.
Use negative position to start from the list end.
Parameters:
Name | Type | Description |
---|---|---|
position |
string | |
value |
string |
setDelimiter(delimiter)
Set list delimiter.
Parameters:
Name | Type | Description |
---|---|---|
delimiter |
string |
shuffle()
Shuffle list in place.
slice(start, end) → {Listing}
Slice list from start to end position.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
start |
number | 0 | = 0 |
end |
number | = list length |
Returns:
sliced list
- Type
- Listing
some(compareFn) → {boolean}
Determines whether at least one list elements satisfy the specified test.
Parameters:
Name | Type | Description |
---|---|---|
compareFn |
function | compare function |
Returns:
- Type
- boolean
sort(compareFn)
Sort list in place.
Parameters:
Name | Type | Description |
---|---|---|
compareFn |
function | compare function |
swap(position1, position2)
Swap list items at given positions.
Use negative position to start from the list end.
Parameters:
Name | Type | Description |
---|---|---|
position1 |
number | |
position2 |
number |
toArray() → {Array.<string>}
Transform list to array based on current delimiter.
Returns:
array
- Type
- Array.<string>
(generator) values()
Get a new Iterator object that contains the values for each list item.