0.3.0 • Published 7 years ago

common-utils-helper v0.3.0

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

common-utils-helper

It is a place to provide helper methods used in NodeJS for common projects.

JSON parse helpers

Date Reviver

You may use the dateReviver function to convert the strings that represents an ISO Date format to a Date Objects instead of strings.

var CommonUtilsHelper = require ('CommonUtilsHelper');
var jsonStr = '{"date":"2017-04-01T12:00:00Z"}';
var obj = JSON.parse(jsonStr, CommonUtilsHelper.JSON.dateReviver);
// The typeof obj.date should be object instead of string

This will convert a sting of type '2017-04-01T12:00:00Z' to a Date object of the same date/time. Access to Date methods would be available directly from the parsed date property.