flodash

Import

Require

Import

import

import.js

Import using esm or TypeScript

Since

1.0.0

Example

import _f from 'flodash'
 
_f.date('3/14/2019', 'uk')
// => 14 Mar 2019
 
_f.addDays('3/6/19', 1, '-')
// => 03-07-2019
 
_f.subtractDays('3/6/19', 1, '-')
// => 03-05-2019

modules

modules.js

Import individual ES Modules using esm or TypeScript

Since

1.0.0

Example

import { addDate, subtractDate } from 'flodash'
 
addDays('3/6/19', 1, '-')
// => 03-07-2019
 
subtractDays('3/6/19', 1, '-')
// => 03-05-2019

Require

require

require.js

Import using require

Since

1.0.0

Example

const _f = require('flodash')
 
_f.date('3/14/2019', 'uk')
// => 14 Mar 2019
 
_f.addDays('3/6/19', 1, '-')
// => 03-07-2019
 
_f.subtractDays('3/6/19', 1, '-')
// => 03-05-2019

“Date” Methods

_f.date(Date, format)

date.js

Computes input date converts to string and returns with specified format.

Since

1.0.0

Arguments

  1. Date (date): options are new Date(), timestamp or string in valid date format. See example below.
  2. format (string):

Returns

(string): Returns the date as a String in specified format.

Example

let any_fate = "1/07/2019"
 
_f.date(any_fate, '/')
// => 01/07/2019
 
_f.date(any_fate, '-')
// => 01-07-2019
 
_f.date(any_fate, '.')
// => 01.07.2019
 
_f.date(any_fate, 'MMM DD YYYY')
// => Jan 07 2019
 
_f.date(any_fate, 'england')
// => 07 Jan 2019
 
_f.date(any_fate, 'uk')
// => 07 Jan 2019
 
_f.date(any_fate, 'full')
// => Mon Jan 07 2019 00:00:00 GMT-0700 (Mountain Standard Time)

_f.now()

now.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(_f.now() - stamp)
}, _f.now())
 
// => Logs milliseconds it took for the deferred invocation.

_f.getTimestamp(Date)

getTimestamp.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

  1. Date (date): to convert to timestamp.

Returns

(number): Returns the timestamp.

Example

_f.getTimestamp('July 4 1776')
// => 121244400000
 
_f.getTimestamp()
// => 1552353178563
// returns now timestamp
 
_f.getTimestamp('11/4/1973')
// => -6106035604000

_f.isDate(value)

isDate.js

Verifies if value is a valid Date object and valid Date.

Since

1.0.0

Arguments

  1. value (*): The value to check.

Returns

(boolean): Returns true if value is a Date object & valid Date, else false.

Example

_f.isDate('3/3/19')
// => true
 
_f.isDate(new Date())
// => true
 
_f.isDate('Jul 4 1776')
// => true
 
_f.isDate(25200000)
// => true
 
_f.isDate('3/33/19')
// => false
 
function getDate() {
    return '1/1/19'
}
_f.isDate(getDate)
// => false
 
_f.isDate(getDate())
// => true

“Math” Methods

_f.addDays(Date, days, format)

addDays.js

Input _fate add nDays with format

Since

1.0.0

Arguments

  1. Date (date):
  2. days (number): to add
  3. format (string):

Example

const any_fate = '3/6/19'
 
_f.addDays(any_fate, 1, '-')
// => 03-07-2019
 
_f.addDays(any_fate, 2, '.')
// => 03.08.2019
 
_f.addDays(any_fate, 3, 'uk')
// => 09 Mar 2019

_f.subtractDays(Date, days, format)

subtractDays.js

Input _fate subtract nDays with format

Since

1.0.0

Arguments

  1. Date (Date):
  2. days (number): to subtract
  3. format (string):

Example

const any_fate = '3/6/19'
 
_f.subtractDays(any_fate, 1, '-')
// => 03-05-2019
 
_f.subtractDays(any_fate, 2, '.')
// => 03.04.2019
 
_f.subtractDays(any_fate, 3, 'uk')
// => 03 Mar 2019