Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

yocto-utils

yoctore36Apache-2.02.2.0

Utility tools for : cryptography, date, media, object, strings

utility, crypto, encode, decode, util, tool, date, string, object

readme

NPM

alt text Code Climate Test Coverage Issue Count Build Status

Overview

This module is a part of yocto node modules for NodeJS.

Please see our NPM repository for complete list of available tools (completed day after day).

This module provide utility function for various domains (encryption, media, string, date, object and more others)

Motivation

After each development, conclusion is the same : we need to create an utility tools with all our utility method to be able to reuse them in other program. That's why we create this utility tools.

Although this module was completed day after day.

Available modules

See method list for each available method

  • Crypto : for utility functions related to encryption (random password, encrypt, decrypt, etc..)
  • Media : for utility functions related to media
  • Request : for utility functions related to request (get http info - host - x-forwarded, etc ...)
  • Strings : for utility functions related to string
  • YDate : for utility functions related to date
  • Object : for utility functions related to object manipulation

Method list

  • Module Crypto :
    • randomizedPassword(length, complexity) : generate a random password with a specific complexity
    • encrypt(key, value) : encrypt given string to an AES-256 representation with given key
    • decrypt(key, value) : decrypt given AES-256 representation string value with given key
  • Module Date :
    • generateList(min, max, prefixMin, prefixMax, reverse) : Generate a list of date between two given index
    • getElapsedTime(config, time) : Get elapsedTime between current time to given time
  • Module Media :
    • isValidImageFormat(type) : Test is given image format is valid (only string extension for the moment)
  • Module Object :
    • renameKey(obj, key, newKey) : rename a given key for another given
    • underscoreKeys(o) : rewrite all base object key name to an underscore key name (FULL depth level)
    • underscorizeKeysMongoose(o) : rewrite all base object key name to an underscore key name (FULL depth level) of an Mongoose object
    • inspect(value, colorize : get the current object to a string representation with a full depth
    • camelizeKeys(o) : rewrite all base object key name to an underscore key name (FULL depth level)
    • camelizeKeysMongoose(o) : rewrite all base object key name to an underscore key name (FULL depth level) of an Mongoose object
  • Module Request :
    • getHost(request) : Get current host name from express request object
  • Module Strings :
    • generateAsciiCharsList(alpha, num, special, toLower) : Generate an list of chars from ascii table
    • isUppercase(char) : test if a given char is to uppercase
    • isLowercase(char) : test if a given char is to lowercase
    • camelCase(string) : camelize a string
    • underscore(string) : underscore a string
    • isSpecialChar(char) : check is a given char is a special char

Logging in tool

By Default this module include yocto-logger for logging.

How to use

Each module is available like : utils.<MODULE_NAME>.<WANTED_METHOD_NAME>(PARAMS, ...)

var utils = require('yocto-utils')();

// For Crypto module
utils.crypto.<METHOD_NAME>

// For Date module
utils.date.<METHOD_NAME>

// For Media module
utils.media.<METHOD_NAME>

// For Object module
utils.obj.<METHOD_NAME>

// For Request module
utils.request.<METHOD_NAME>

// For Strings module
utils.str.<METHOD_NAME>

Or you can retreive module by getter method : utils.get('module_name')


// For Crypto module
utils.get('crypto').<METHOD_NAME>

// For Date module
utils.get('date')<METHOD_NAME>

// For Media module
utils.get('media')<METHOD_NAME>

// For Object module
utils.get('obj')<METHOD_NAME>

// For Request module
utils.get('request')<METHOD_NAME>

// For Strings module
utils.get('str')<METHOD_NAME>

Examples

Examples are available in example directory in git repository.

Next step

  • Other utilities function

changelog

2.1.0 (2018-03-20)

  • Update crypto module to use a specific algorithm as a params if is requested

2.0.0 (2018-02-15)

  • Major update of all dependencies
  • Update node version engine to >= 8.9.4

1.2.4 (2016-03-01)

Package update and travis & codeclimage integration

1.2.3 (2016-03-01)

  • Change request module usage

1.2.0 (2016-01-20)

  • Add function camelizeKeysMongoose that camelize keys of an Mongoose object
  • Add function underscorizeKeysMongoose that underscorize keys of an Mongoose object

1.1.1 & 1.1.2 (2015-11-17)

  • Fix a bug on camelize and underscore for complex object

1.1.0 (2015-11-04)

  • Update Str.underscoreKeys and Str.camelizeKeys to keep safe first char of given key if is a special char
  • Add a new method isSpecilaChar in Str module : to check if a given char is a special char

1.0.1 (2015-11-04)

  • Add isJoi test on object before process full depth key

1.0.0 (2015-11-03)

  • Add a camelize / underscore string function
  • Change underscoreKeys and camelizeKeys method to process full deph of current object

0.8.1 (2015-10-19)

  • Return false on encrypt / decrypt fn

0.8.0 (2015-10-12)

  • Add camelizeKeys method on object module : rename first depth level key to camelize style

0.7.1 & 0.7.3 (2015-09-21)

  • Change readme.md content

0.7.1 & 0.7.2 (2015-09-21)

  • Minor fixes & Change readme.md content & removing old documentation

0.7.0 (2015-09-21)

Adding renameKeys function in object module.

0.6.0 (2015-09-21)

Adding new modules & functions :

Crypto Module :

  • randomizedPassword : generate a random password
  • encrypt : encrypt given string
  • decrypt : decrypt a value encrypted with encrypt function

0.5.0 (2015-09-21)

Adding new modules & functions :

Date Module :

  • generateList : Generate a list of date between two given index

0.4.0 (2015-09-21)

Adding new modules & functions :

Media Module :

  • isValidImageFormat : Test is given image format is valid

0.3.0 (2015-09-21)

Adding new modules & functions :

Object Module :

  • renameKey : rename a given key for another given
  • inpect : get the current object to a string representation with a full depth

0.2.0 (2015-09-21)

Adding new modules & functions :

Request Module :

  • getHost : Get current host name from request object

0.1.0 (2015-09-21)

Adding new modules & functions :

Strings Module :

  • generateAsciiCharsList : Generate an list of chars from ascii table
  • isUppercase : test if a given char is to uppercase
  • isLowercase : test if a given char is to lowercase