cap-helpers
v1.0.2
Published
Helper functions for CAP Distributing
Readme
CAP Distributing's JavaScript Helpers
We created this package so we could easily share these basic function across all of our applications.
Usage
It returns the following functions:
- sortArray: a function that takes 2 parameters (Array to sort, and key to sort on) and returns a sorted array. For example:
var capHelpers = require('cap-helpers'); var myArray = [{name: 'Zach'}, {name: 'Jamie'}]; capHelpers.sortArray(myArray, ['name']); // returns [{name: 'Jamie'}, {name: 'Zach'}]
- toBase64: a function that converts the given value to base64. For example:
var capHelpers = require('cap-helpers'); var value = 'this is a string!!'; capHelpers.toBase64(value); // returns 'dGhpcyBpcyBhIHN0cmluZyEh'
- fromBase64: a function that converts the given value from base64. For example:
var capHelpers = require('cap-helpers'); var value = 'dGhpcyBpcyBhIHN0cmluZyEh'; capHelpers.fromBase64(value); // returns 'this is a string!!'
- orderObject: a function that orders an object's keys alphabetically. For example:
var capHelpers = require('cap-helpers'); var myObj = {name: 'Jamie', age: 25}; capHelpers.orderObject(myObj); // returns {age: 25, name: 'Jamie'}
- numberWithCommas: a function that converts a number to a string with commas. For example:
var capHelpers = require('cap-helpers'); var num = 1234567.89; capHelpers.numberWithCommas(num); // returns '1,234,567.89'
- camelcaseToUnderscore: a function that takes a camelcased string, object or array and converts it to underscores. For example:
var capHelpers = require('cap-helpers'); var str = 'myString'; capHelpers.camelcaseToUnderscore(str); // returns 'my_string'
- underscoreToCamelcase: a function that takes an underscored string, object or array and converts it to camelcase. For example:
var capHelpers = require('cap-helpers'); var str = 'my_string'; capHelpers.underscoreToCamelcase(str); // returns 'myString'
- underscoreToTitlecase: a function that takes an underscored string, object or array and converts it to titlecase. For example:
var capHelpers = require('cap-helpers'); var str = 'my_string'; capHelpers.underscoreToTitlecase(str); // returns 'MyString'
- titlecaseToCamelcase: a function that takes a titlecased string, object or array and converts it to camelcase. For example:
var capHelpers = require('cap-helpers'); var str = 'MyString'; capHelpers.titlecaseToCamelcase(str); // returns 'myString'
Testing
npm test> Runs all the tests and checks the code coverage.npm run single-test> Runs all the tests once.npm run watch-test> Runs all the tests and watches for changes.npm run check-coverage> Checks the code coverage (this should be ran after running the tests).
