settings

declaration
 settings 

Global settings

var settings = require('../settings');

class Tokei {
  constructor(locale) {

Intl

property
 this.Intl 

Set Intl Alias

this.Intl = {
  'Date': intl.DateTimeFormat,
  'Number': intl.NumberFormat
};

Set private variables

// Set the current date
this._date = moment();
// Set the initial number
this._number = 0;
// Set the locale
this._locale = locale || settings.locale;
// Set moment
this._moment = moment;
// Set moment to global locale
this._moment.locale(locale || settings.locale);
// Determines if the chain is formatting a number
this._isNumber = false;
    }

now

method
 now() 

Returns the current date or time

now() {

Example

Get the current date

// Returns the current date
tokei().date().now();

Get the current time

// Returns the current time
tokei().time().now();
return new this.Intl.Date(this._locale, this._options).format(moment());
    }

date

method
 date() 

Option name Type Description
options Object

The options for date formatting.

return Tokei

this

Formats the date.
See DateTimeFormat.

date(options) {

Example

Get the formatted date.

tokei().date().format(new Date(Date.UTC(2012, 11, 20, 3, 0, 0)));

Get the formatted date with options.

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
tokei('de-DE').date(options).format(new Date(Date.UTC(2012, 11, 20, 3, 0, 0)));

time

method
 time() 

Formats the time.
See DateTimeFormat.

time(options) {

Example

Get the formatted time.

tokei('en-AU').time().format(new Date(Date.UTC(2012, 11, 20, 3, 0, 0)));

Get the formatted time with options.

var options =  { hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short' };
tokei('en-AU').time(options).format(new Date(Date.UTC(2012, 11, 20, 3, 0, 0)));

number

method
 number() 

Formats the time.
See NumberFormat.

number(options) {

Example

Get the formatted number.

tokei('de-DE').number().format(123456.789);

Get the formatted number with options.

var options =  { style: 'currency', currency: 'EUR' };
tokei('de-DE').number(options).format(123456.789);

format

method
 format() 

Option name Type Description
obj Date, Number

The object to format.

return String, Number

The formatted date, time or number.

Formats the object
See DateTimeFormat
and NumberFormat

format(obj) {

Example

Get the formatted date, time, or number.

//format date
tokei().date().format([Date date]);
//format time
tokei().time().format([Date time]);
//format number
tokei().number().format([Number number]);

moment

method
 moment() 

Option name Type Description
arguments
return Moment

The local moment.
See moment

moment() {

Example

Using moment with Tokei.

//use moment just as you would normally
tokei().moment();
//you can even set a locale
tokei('ja').moment();
return this._moment.apply(this, arguments);
  }
}

tokei

function
 tokei() 

Option name Type Description
locale String

The local locale to set.

return Tokei

The Tokei instance.

Creates an instance of Tokei.

var tokei = function(locale) {

Example

Get the formatted date, time, or number.

tokei().date().format();
//usage:
//tokei().[api]().format()

Setting the locale.

tokei('ja').date().format()
//usage:
//tokei([String locale]).[api]().format()
return new Tokei(locale);
};

locale

method
 tokei.locale() 

Option name Type Description
locale Object

The global locale.

return Object

The global locale.

tokei.locale = function(locale) {
  settings.locale = locale;
  return settings.locale;
};

config

method
 tokei.config() 

Option name Type Description
options Object

The global options.

return Object

The global options.

tokei.config = function(options) {
  settings.options = options || settings.options;
  return settings.options;
};

moment

property
 tokei.moment 

The global moment. See Moment.js.

tokei.moment = moment;

export default tokei;