Socket
Book a DemoInstallSign in
Socket

es-abstract-to-length

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-abstract-to-length

A method to convert an argument to an integer suitable for use as the length of an array-like object. This method follows ECMAScript's specification for the 'ToLength' abstract operation.

0.1.1
latest
Source
npmnpm
Version published
Weekly downloads
9
800%
Maintainers
1
Weekly downloads
 
Created
Source

ToLength

A method to convert an argument to an integer suitable for use as the length of an array-like object. This method follows ECMAScript's specification for the 'ToLength' abstract operation.

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

Installation Using npm

npm install es-abstract-to-length

Example Usage

var toLength = require('es-abstract-to-length')

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

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

console.log(toLength(-Infinity)) // =>    0
console.log(toLength(Infinity))  // => 9007199254740991

Documentation

API

ToLength ( argument )

The abstract operation ToLength converts argument to an integer suitable for use as the length of an array-like object.

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.

Keywords

ToLength

FAQs

Package last updated on 09 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.