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

Package detail

es-abstract-to-integer

npetruzzelli16BSD-3-Clause0.1.2

A method to convert the argument to an integral numeric value. This method follows ECMAScript's specification for the 'ToInteger' abstract operation.

ToInteger, toInteger, to integer, integer, ECMAScript, ES, ecma, abstract, internal, operation, method, abstract operation, abstract operations, internal method, internal methods, JavaScript, ES5, ES2009, ES5.1, ES2011, ES6, ES2015, ES7, ES2016, ES8, ES2017

readme

ToInteger

A method to convert the argument to an integral numeric value. This method follows ECMAScript's specification for the 'ToInteger' abstract operation.

Currently, this module only supports the ES2017 (ES8) specification.

Installation Using npm

npm install es-abstract-to-integer

Example Usage

var toInteger = require('es-abstract-to-integer')

console.log(toInteger(-3.14))  // =>   -3
console.log(toInteger(3.14))   // =>    3
console.log(toInteger(42))     // =>   42
console.log(toInteger("9001")) // => 9001
console.log(toInteger(null))   // =>    0
console.log(toInteger(false))  // =>    0
console.log(toInteger(true))   // =>    1

console.log(toInteger("foo"))  // =>    0
console.log(toInteger({}))     // =>    0
console.log(toInteger([]))     // =>    0

var d = new Date(2015, 3, 14, 0, 0, 0, 0)
console.log(toInteger(d)) // => 1428984000000

Documentation

API

ToInteger ( argument )

The abstract operation ToInteger converts argument to an integral numeric value.

A Number value is returned.

A TypeError exception may be thrown for arguments that are Symbols or Objects that lack a valueOf method or a toString method capable of returning a non-object value.

argument

Type: *

The value to convert.

  • es-abstract: a single library for multiple ECMAScript abstract operations.