mellotron 0.2.6
Synthetic string orchestra. Curated list of string manipulation curried functions
yarn add mellotron
npm install mellotron
Methods
capitalize concat contains deburr endsWith format fromQuery fromURL isString isURL join leftPad length match pad replace reverse rightPad slugify split startsWith test toLower toQuery toString toUpper toURL trim trimLeft trimRight
capitalize([string=''])
Capitalize the first letter of a string
.
From lodash/capitalize
Parameters
Name | Type | Description | |
---|---|---|---|
string='' | string |
The string to convert. | Optional |
Examples
;// => 'United states'
Returns
string
Returns the capitalized string.
concat([string='', string=''])
Concatenate the given strings
.
From ramda/concat
Parameters
Name | Type | Description | |
---|---|---|---|
string='' | string |
The first string to add. | Optional |
string='' | string |
The second string to add. | Optional |
Examples
;// => 'ABCDEF' const prefix = ;;// => 'cyberspace'
Returns
string
Returns the result of concatenating the givenstrings
.
contains(a, list)
Inserts the separator string
between each element and concatenating all the elements into a single string
.
From ramda/contains
Parameters
Name | Type | Description | |
---|---|---|---|
a | string |
The item to compare against. | |
list | string |
The string to consider |
Examples
// => true const taco = ;;// => true
Returns
boolean
Returnstrue
if an equivalent item is in list,false
otherwise.
deburr([string=''])
Deburrs string
by converting letters to basic Latin letters and removing combining diacritical marks.
From lodash/deburr
Parameters
Name | Type | Description | |
---|---|---|---|
string='' | string |
The string to deburr. | Optional |
Examples
;// => 'deja vu'
Returns
string
Returns the deburred string.
endsWith(target, string)
Checks if string
ends with the given target string
.
From lodash/endsWith
Parameters
Name | Type | Description | |
---|---|---|---|
target | string |
The string to search for. | |
string | string |
The string to inspect. |
Examples
;// => true const endsWithR = ;;// => true
Returns
boolean
Returnstrue
ifstring
ends withtarget
, elsefalse
.
format(template, values)
Values are interpolated on a template string
.
Parameters
Name | Type | Description | |
---|---|---|---|
template | string |
The `string` with placeholders. | |
values | Array.<*> Object |
Values to be interpolated |
Examples
// Allows creating templates:const readMessages = // => 'Holly, you have 2 unread messages' // Unmatched placeholders produce no output:// => 'Steve, you have 1 unread message' // Supports property access via dot notationconst bobby = first: 'Bobby' last: 'Fischer' ;const garry = first: 'Garry' last: 'Kasparov' ;// => 'Bobby Fischer vs. Garry Kasparov' // Supports property access via object propertyconst jamesBond = firstname: 'James' lastname: 'Bond' ;// => 'The name is Bond. James Bond.'
Returns
string
Returns the result of replacing each {…} placeholder in the template string with its corresponding replacement.
fromQuery(str[, sep='&', eq='=', options])
Parse a query string into an object. From querystring/parse
Parameters
Name | Type | Description | |
---|---|---|---|
str | string |
The URL query string to parse. | |
sep='&' | string |
The substring to delimit key and value pairs. | Optional |
eq='=' | string |
The substring to delimit keys and values. | Optional |
options | Object |
Optional |
Examples
;// => { foo: ['1', '2', '3' ] } ;// => { foo: ['1', '2', '3' ] }
Returns
Object
Returns the parsed URL query string (str) into a collection of key and value pairs.
fromURL(urlString[, parseQueryString=false, slashesDenoteHost=false])
Parse a query string into an object. Leading ? or # are ignored, so you can pass location.search or location.hash directly. From url/parse
Parameters
Name | Type | Description | |
---|---|---|---|
urlString | string |
The URL string to parse. | |
parseQueryString=false | boolean |
The query property will be set to an object returned by the querystring module's parse() method if `true`. | Optional |
slashesDenoteHost=false | boolean |
The first token after the literal string // and preceding the next / will be interpreted as the host if `true`. | Optional |
Examples
;// =>// {// protocol: 'https:',// slashes: true,// auth: null,// host: 'www.dgmlive.com',// port: null,// hostname: 'www.dgmlive.com',// hash: '#track-1',// search: '?album=discipline',// query: 'album=discipline',// pathname: '/kingcrimson/',// path: '/kingcrimson/?album=discipline',// href: 'https://www.dgmlive.com/kingcrimson/?album=discipline#track-1'// }
Returns
Object
Returns the parsed URL into a collection of key and value pairs.
isString(val)
See if an object is an instance of the String constructor. From ramda/is
Parameters
Name | Type | Description | |
---|---|---|---|
val | string |
The value to test. |
Examples
;// => true ;// => true
Returns
boolean
Returns if the value is a String.
isURL(string)
Parse a query string into an object. Leading ? or # are ignored, so you can pass location.search or location.hash directly. From url/parse
Parameters
Name | Type | Description | |
---|---|---|---|
string | string |
The URL string to validate. |
Examples
;// => true // => false // => false
Returns
Object
Returns true if string is a URL, false otherwise.
join(separator, xs)
Inserts the separator string
between each element and concatenating all the elements into a single string
.
From ramda/join
Parameters
Name | Type | Description | |
---|---|---|---|
separator | string |
The string used to separate the elements. | |
xs | string |
The elements to join into a string. |
Examples
;// => 'a 2 3.4' const piper = ;;// => 'Pied|Piper|of|Hamelin'
Returns
string
Returns thestring
made by concatenatingxs
withseparator
.
leftPad(length, string)
Pads string
on the left side if it's shorter than length
. Padding characters are truncated if they exceed length
.
From lodash/padStart
Parameters
Name | Type | Description | |
---|---|---|---|
length | number |
The padding length. | |
string | string |
The string to pad. |
Examples
;// => ' abc'
Returns
string
Returns the padded string.
length(s)
Count visual length of javascript string. From charcount
Parameters
Name | Type | Description | |
---|---|---|---|
s | string |
The string to count. |
Examples
;// => 12
Returns
number
Returns length of the string.
match(rx, str)
Tests a regular expression against a string
.
From ramda/match
Parameters
Name | Type | Description | |
---|---|---|---|
rx | string |
A regular expression or a substring to match. | |
str | string |
The string to match against. |
Examples
;// => ['ba', 'na', 'na']
Returns
Array
The list of matches or emptyarray
.
pad(length, string)
Pads string
on the left and right sides if it's shorter than length
. Padding characters are truncated if they can't be evenly divided by length
.
From lodash/pad
Parameters
Name | Type | Description | |
---|---|---|---|
length | number |
The padding length. | |
string | string |
The string to pad. |
Examples
;// => ' abc '
Returns
string
Returns the padded string.
replace(regex, replacement, str)
Inserts the separator string
between each element and concatenating all the elements into a single string
.
From ramda/replace
Parameters
Name | Type | Description | |
---|---|---|---|
regex | string |
A regular expression or a substring to match. | |
replacement | string |
The string to replace the matches with. | |
str | string |
The String to do the search and replacement in. |
Examples
;// => 'bar bar bar' const censor = ;// => "Let's spend some time together"
Returns
string
Returns the resultedstring
.
reverse(list)
Reverse a string
.
From ramda/reverse
Parameters
Name | Type | Description | |
---|---|---|---|
list | string |
The string to reverse. |
Examples
;// => 'desserts'
Returns
string
Returns a new string with the characters in reverse order.
rightPad(length, string)
Pads string
on the right side if it's shorter than length
. Padding characters are truncated if they exceed length
.
From lodash/padEnd
Parameters
Name | Type | Description | |
---|---|---|---|
length | number |
The padding length. | |
string | string |
The string to pad. |
Examples
;// => 'abc '
Returns
string
Returns the padded string.
slugify([string=''])
Converts string
to kebab case.
From lodash/kebabCase
Parameters
Name | Type | Description | |
---|---|---|---|
string='' | string |
The string to convert. | Optional |
Examples
;// => 'this-that-and-the-other-an-outre-collection'
Returns
string
Returns the kebab cased string.
split(sep, str)
Splits a string
into an array
of strings based on the given separator.
From ramda/split
Parameters
Name | Type | Description | |
---|---|---|---|
sep | string |
The pattern. | |
str | string |
The string to separate into an array. |
Examples
const path = ;;// => ['', 'usr', 'local', 'bin', 'node']
Returns
Array
Returns the resulting array.
startsWith(target, string)
Checks if string
starts with the given target string
.
From lodash/startsWith
Parameters
Name | Type | Description | |
---|---|---|---|
target | string |
The string to search for. | |
string | string |
The string to inspect. |
Examples
;// => true const startsWithM = ;;// => true
Returns
boolean
Returnstrue
ifstring
starts withtarget
, elsefalse
.
test(pattern, str)
Determines whether a given string
matches a given regular expression.
From ramda/test
Parameters
Name | Type | Description | |
---|---|---|---|
pattern | string |
A regular expression or a substring to match. | |
str | string |
The string to match against. |
Examples
;// => true ;// => false
Returns
boolean
The result of the test.
toLower(str)
Convert to lower case. From ramda/toLower
Parameters
Name | Type | Description | |
---|---|---|---|
str | string |
The string to lower case. |
Examples
;// => 'xyz'
Returns
string
Returns the lower case version ofstr
.
toQuery(str[, sep='&', eq='=', options])
Stringify an object into a query string, sorting the keys. From querystring/stringify
Parameters
Name | Type | Description | |
---|---|---|---|
str | string |
The URL query string to parse. | |
sep='&' | string |
The substring to delimit key and value pairs. | Optional |
eq='=' | string |
The substring to delimit keys and values. | Optional |
options | Object |
Optional |
Examples
;// => 'foo=bar&baz=qux&baz=quux&corge=' ;// => foo:bar|baz:qux'
Returns
Object
Returns the parsed URL query string (str) into a collection of key and value pairs.
toString(val)
Convert to string
.
From ramda/toString
Parameters
Name | Type | Description | |
---|---|---|---|
val | string |
The value to convert. |
Examples
;// => '42' ;//=> '[1, 2, 3]' ;//=> '{"bar": 2, "baz": 3, "foo": 1}'
Returns
string
Returns the string representation of the given value
toUpper(str)
Convert to upper case. From ramda/toUpper
Parameters
Name | Type | Description | |
---|---|---|---|
str | string |
The string to upper case. |
Examples
;// => 'ABC'
Returns
string
Returns the upper case version ofstr
.
toURL(urlObject)
Convert an url object to URL. From url/format
Parameters
Name | Type | Description | |
---|---|---|---|
urlObject | Object string |
A URL object (as returned by url.parse() or constructed otherwise). If a string, it is converted to an object by passing it to url.parse(). |
Examples
// => "https://www.dgmlive.com/kingcrimson?album=discipline#track-1"
Returns
string
Returns the resulted URL.
trim(str)
Removes (strips) whitespace from both ends of the string. From ramda/trim
Parameters
Name | Type | Description | |
---|---|---|---|
str | string |
The string to trim. |
Examples
;// => 'xyz'
Returns
string
Returns the trimmed version ofstr
.
trimLeft([string=''])
Removes leading whitespace or specified characters from string
.
From lodash/trimStart
Parameters
Name | Type | Description | |
---|---|---|---|
string='' | string |
The string to trim. | Optional |
Examples
;// => 'abc '
Returns
string
Returns the trimmed string.
trimRight([string=''])
Removes trailing whitespace or specified characters from string
.
From lodash/trimEnd
Parameters
Name | Type | Description | |
---|---|---|---|
string='' | string |
The string to trim. | Optional |
Examples
;// => ' abc'
Returns
string
Returns the trimmed string.