New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

better-js-integer

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

better-js-integer

A better way to ensafe javascript integers from being treated as octal numbers

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

A better way to ensafe javascript integers from being treated as octal numbers

Javascript flaw on integers base, dealing with octal numbers (Out of strict mode):

when you pass an integer with leading zeros such as 0112 to any javascript operator, it looks inside the digits, if all digits are less than 8, it behaves like your integer is in base 8 (Octal) and converts it internally to base 10. But if you integer has any digit greater than or equal to 8, Javascript will treat the integer as an integer in base 10.

This is why if you evalute 0112 + 1 in any javascript console, you'll get the output of 75. Becase 0112 has digits all less than 8, javascript treats it as an octal number and converts it to base 10, so the result would 74.

0112(8) ==> 74(10)

Installation and Usage

npm install better-js-integer --save

import { ensafe } from 'js-better-integer'

ensafe(0122) // returns 122

Development

Be sure to write and run tests before sending any PR!

To run tests: npm test

Credit: Farzad YZ farskid@gmail.com MIT Licensed.

FAQs

Package last updated on 09 May 2017

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