string

Helpers for common string manipulation

Source:

Methods

(inner) appendStr(a, b) → {String}

Produces a new string by adding the first argument to the end of the second

Parameters:
Name Type Description
a String

string to add

b String

stirng to begin with

Source:
Returns:

concatenated result

Type
String
Example
const insultSomeone = appendStr(' are bad at golf')

insultSomeone('you')
//=> 'you are bad at golf'

(inner) buildQueryString(tuples) → {String}

Takes an array of tuples where the first element is a param name and the second element is a param value, returns a standard url querystring

Parameters:
Name Type Description
tuples Array.<Array>

pairs of param names and values

Source:
Returns:

standard url querystring

Type
String
Example
const tuples = [
  ['param1', 'value1'],
  ['param2', 'value2'],
]

buildQueryString(tuples) = //=> 'param1=value1&param2=value'

(inner) camelize(str) → {String}

Converts text to camel case

Parameters:
Name Type Description
str String

string to convert

Source:
Returns:

camel cased string

Type
String
Example
camelize('moz_transform')
// => 'MozTransform'

(inner) firstCharIs(matchString, testString) → {Boolean}

Returns a curried function that checks its first argument matches the first character of its second argument

Parameters:
Name Type Description
matchString String

string to match against

testString String

string to test

Source:
Returns:

true if the first character of testString is equal to the matchString

Type
Boolean
Example
const one = 'one'
firstCharIs('o', one) //=> true
firstCharIs('t', one) //=> false

const two = 'two'
firstCharIs('t', two) //=> true
firstCharIs('o', two) //=> false

(inner) insertCommasInNumber(val) → {String}

Takes a string or integer and returns a stringified version with comma insertion

Parameters:
Name Type Description
val String | Number

number to format

Source:
Returns:

formatted string

Type
String
Example
insertCommasInNumber('20000') //=> '20,000'
insertCommasInNumber(2000) //=> '2,000'
insertCommasInNumber(200) //=> '200'

(inner) makeRegexs(tests) → {Object}

Takes a list of strings, and returns an object where each string is used as a key to expose a simple regex pattern

Parameters:
Name Type Description
tests Array.<string>

strings to base simple regex patterns on

Source:
Returns:
Type
Object
Example
const patterns = makeRegexs(['a', 'b'])
patterns.b('best') //=> true
patterns.b('rest') //=> false

(inner) snakeify(str) → {String}

Converts text to snake case

Parameters:
Name Type Description
str String

string to convert

Source:
Returns:

snkae cased string

Type
String
Example
snakeify('MozTransform')
// => 'moz_transform'