Test Node Typescript
Test Driven Node v10 Typescript Web App
nodedash v1.0.0
Import
Require
Date
Math
Import
_n._n_import
nodedash.js
Import using esm
or TypeScript
Since
1.0.0
Example
import _n from 'nodedash'
_n.date('3/14/2019', 'uk')
// => 14 Mar 2019
_n.addDays('3/6/19', 1, '-')
// => 03-07-2019
_n.subtractDays('3/6/19', 1, '-')
// => 03-05-2019
_n._n_modules
nodedash.js
Import individual ES Modules using esm
or TypeScript
Since
1.0.0
Example
import { addDate, subtractDate } from 'nodedash'
addDays('3/6/19', 1, '-')
// => 03-07-2019
subtractDays('3/6/19', 1, '-')
// => 03-05-2019
Require
_n.require
nodedash.js
Import using require
Since
1.0.0
Example
const _n = require('nodedash')
_n.date('3/14/2019', 'uk')
// => 14 Mar 2019
_n.addDays('3/6/19', 1, '-')
// => 03-07-2019
_n.subtractDays('3/6/19', 1, '-')
// => 03-05-2019
“Date” Methods
_n.date(Date, format)
nodedash.js
Computes input date
converts to string and returns with specified format
.
Since
1.0.0
Arguments
-
Date
(date): options arenew Date()
,timestamp
orstring
in valid date format. See example below. -
format
(string):
Returns
(string): Returns the date as a String in specified format.
Example
let any_nate = "1/07/2019"
_n.date(any_nate, '/')
// => 01/07/2019
_n.date(any_nate, '-')
// => 01-07-2019
_n.date(any_nate, '.')
// => 01.07.2019
_n.date(any_nate, 'MMM DD YYYY')
// => Jan 07 2019
_n.date(any_nate, 'england')
// => 07 Jan 2019
_n.date(any_nate, 'uk')
// => 07 Jan 2019
_n.date(any_nate, 'full')
// => Mon Jan 07 2019 00:00:00 GMT-0700 (Mountain Standard Time)
_n.now()
nodedash.js
Gets the timestamp of the number of milliseconds that have elapsed since
the Unix epoch (1 January 1970 00
:00:00 UTC).
Since
1.0.0
Returns
(number): Returns the timestamp.
Example
const { defer } = require('lodash')
defer(function(stamp) {
console.log(_n.now() - stamp)
}, _n.now())
// => Logs milliseconds it took for the deferred invocation.
_n.getTimestamp(Date)
nodedash.js
Gets the timestamp of the number of milliseconds that have elapsed since
date
argument. If date
is undefined
it gives milliseconds elapsed since
the Unix epoch (1 January 1970 00
:00:00 UTC).
Since
1.0.0
Arguments
-
Date
(date): to convert to timestamp.
Returns
(number): Returns the timestamp.
Example
_n.getTimestamp('July 4 1776')
// => 121244400000
_n.getTimestamp()
// => 1552353178563
// returns now timestamp
_n.getTimestamp('11/4/1973')
// => -6106035604000
_n.isDate(value)
nodedash.js
Verifies if value
is a valid Date object
and valid Date
.
Since
1.0.0
Arguments
-
value
(*): The value to check.
Returns
(boolean): Returns true
if value
is a Date object
& valid Date
, else false
.
Example
_n.isDate('3/3/19')
// => true
_n.isDate(new Date())
// => true
_n.isDate('Jul 4 1776')
// => true
_n.isDate(25200000)
// => true
_n.isDate('3/33/19')
// => false
function getDate() {
return '1/1/19'
}
_n.isDate(getDate)
// => false
_n.isDate(getDate())
// => true
“Math” Methods
_n.addDays(Date, days, format)
nodedash.js
Input _nate
add nDays
with format
Since
1.0.0
Arguments
-
Date
(date): -
days
(number): to add -
format
(string):
Example
const any_nate = '3/6/19'
_n.addDays(any_nate, 1, '-')
// => 03-07-2019
_n.addDays(any_nate, 2, '.')
// => 03.08.2019
_n.addDays(any_nate, 3, 'uk')
// => 09 Mar 2019
_n.subtractDays(Date, days, format)
nodedash.js
Input _nate
subtract nDays
with format
Since
1.0.0
Arguments
-
Date
(Date): -
days
(number): to subtract -
format
(string):
Example
const any_nate = '3/6/19'
_n.subtractDays(any_nate, 1, '-')
// => 03-05-2019
_n.subtractDays(any_nate, 2, '.')
// => 03.04.2019
_n.subtractDays(any_nate, 3, 'uk')
// => 03 Mar 2019