A bunch of utility functions
Methods
capitalize(string) → {String}
Capitalize string
Parameters:
| Name | Type | Description | 
|---|---|---|
| string | String | 
Returns:
- Type
- String
Example
util.capitalize('lowercase')
=> "Lowercase"convertKeysToCamelCase(object) → {Object}
Convert object keys to camel case
Parameters:
| Name | Type | Description | 
|---|---|---|
| object | Object | 
Returns:
- Type
- Object
Example
util.toSnakeCase({'hello-world': 'test'})
=> {'helloWorld': 'test'}convertKeysToSnakeCase(object) → {Object}
Convert object keys to snake case
Parameters:
| Name | Type | Description | 
|---|---|---|
| object | Object | 
Returns:
- Type
- Object
Example
util.toSnakeCase({'helloWorld': 'test'})
=> {'hello_world': 'test'}degrees(radian) → {Number}
Convert from radian to degrees
Parameters:
| Name | Type | Description | 
|---|---|---|
| radian | Number | 
Returns:
- Type
- Number
extendAttributes(prefix, defaults, attributes) → {Object}
Extend default values with attribute
Parameters:
| Name | Type | Description | 
|---|---|---|
| prefix | String | Prefix of all attributes | 
| defaults | Object | Default set of attributes | 
| attributes | Object | User set attributes | 
Returns:
- Type
- Object
getQueryString(url, name) → {String}
Return param value in querystring
Parameters:
| Name | Type | Description | 
|---|---|---|
| url | String | |
| name | String | 
Returns:
- Type
- String
Example
util.getQueryString('http://www.example.com/macgyver?season=1&episode=3&time=12:23', 'episode')
=> 3hex2rgb(hex) → {Object}
Convert hex color value to rgb
Parameters:
| Name | Type | Description | 
|---|---|---|
| hex | String | 
Returns:
Object with r, g, and b values
- Type
- Object
parseUrlPath(fullPath) → {Object}
Parameters:
| Name | Type | Description | 
|---|---|---|
| fullPath | String | 
Returns:
- Type
- Object
Example
util.parseUrlPath('http://www.example.com/macgyver?season=1&episode=3&time=12:23')
=> {
  fullPath: 'http://www.example.com/macgyver?season=1&episode=3&time=12:23',
  path: 'http://www.example.com',
  pathComponents: [
    'http:', '', 'www.example.com', 'macgyver'
  ],
  verb: 'macgyver',
  queryies: {
    season: '1',
    episode: '3',
    time: '12:23'
  }
}pluralize(string, count, includeCount) → {String}
Pluralize string based on the count
Parameters:
| Name | Type | Description | 
|---|---|---|
| string | String | String to pluralize (default '') | 
| count | Integer | Object counts | 
| includeCount | Boolean | Include the number or not (default false) | 
Returns:
Pluralized string based on the count
- Type
- String
Example
util.pluralize("apple", 5)
=> "apples"
util.pluralize("apple", 10, true)
=> "10 apples"pyth(a, b) → {Integer}
pythagoras theorem
Parameters:
| Name | Type | Description | 
|---|---|---|
| a | Integer | |
| b | Integer | 
Returns:
- Type
- Integer
radian(degrees) → {Number}
Convert degree to radian
Parameters:
| Name | Type | Description | 
|---|---|---|
| degrees | Number | 
Returns:
- Type
- Number
toCamelCase(string) → {String}
Convert string with dashes, underscores and spaces to camel case
Parameters:
| Name | Type | Description | 
|---|---|---|
| string | String | 
Returns:
- Type
- String
Example
this-is-a-test => thisIsATest
another_test => anotherTest
hello world again => helloWorldAgain
a mix_of-everything => aMixOfEverythingtoSnakeCase(string) → {String}
Convert other cases into snake case (separated by underscores)
Parameters:
| Name | Type | Description | 
|---|---|---|
| string | String | 
Returns:
- Type
- String
Example
util.toSnakeCase("just another string")
=> "just_another_string"trim(string) → {String}
Trimming whitespaces on strings
Parameters:
| Name | Type | Description | 
|---|---|---|
| string | String | input | 
Returns:
Trimmed string
- Type
- String
uncapitalize(string) → {String}
Convert the first character to lowercase
Parameters:
| Name | Type | Description | 
|---|---|---|
| string | String | 
Returns:
- Type
- String
Example
util.uncapitalize('UPPERCASE')
=> "uPPERCASE"validateEmail(email) → {Boolean}
Check if input string is a valid email address
Parameters:
| Name | Type | Description | 
|---|---|---|
| email | String | 
Returns:
- Type
- Boolean
validateTime(time) → {Object}
Check if time input match time regex
Parameters:
| Name | Type | Description | 
|---|---|---|
| time | String | 
Returns:
- Type
- Object
validateUrl(url) → {Object}
Parse url
Parameters:
| Name | Type | Description | 
|---|---|---|
| url | String | 
Returns:
Object with url sections parsed out
- Type
- Object
Example
input: www.example.com:9000/testing
 output: {
   url: 'www.example.com:9000/testing',
   protocol: 'http',
   subdomain: 'www',
   name: 'example',
   domain: 'com',
   port: '9000',
   path: '/testing'
 }