0.0.0 • Published 2 years ago

0o v0.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

0o

A JavaScript octal number parser.

Node.js's support for ECMAScript 2015(ES6) octal literals(0o)

4.3.2 and above0.12.160.10.47 and below
SupportedSupported(with harmony flag)Unsupported

But require("0o") works on all the versions of Node.js & web browsers! XD

Features

  • Works well on both web browsers and Node.js
  • Works in strict mode
  • No dependency
  • Standard JavaScript with high compatibility
  • Does not ignore the sign of -0
  • You can make it accepts NaN and infinite values if you want

require("0o") vs parseInt(..., 8) & require("octal")

require("0o"); it's very clear, and WTF-less.

require("0o")(true)require("0o")()parseInt(..., 8) and require("octal")
0000
-0-0-00
-10-8-8-8
InfinityInvalidArgumentErrorInfinityNaN
-InfinityInvalidArgumentError-InfinityNaN
NaNInvalidArgumentErrorNaNNaN
-NaNInvalidArgumentErrorNaNNaN
9InvalidArgumentErrorInvalidArgumentErrorNaN
"0+10"InvalidArgumentErrorInvalidArgumentError0
"-00010"-8-8-8
"\n\n+10 \n\r\t"888
"LOL"InvalidArgumentErrorInvalidArgumentErrorNaN
"\n\t\r -Infinity \n"InvalidArgumentError-InfinityNaN
undefinedInvalidArgumentErrorInvalidArgumentErrorNaN
""InvalidArgumentErrorInvalidArgumentErrorNaN
"+9"InvalidArgumentErrorInvalidArgumentErrorNaN

Example

var Oo = require("0o")(true);
// If `notational` is true, NaN and infinite values are not allowed;
// otherwise, they are allowed.

console.log("+0o0 is mathematically equivalent to ", Oo(+0)); // 0
console.log("-0o0 is mathematically equivalent to ", Oo(-0)); // -0

console.log("parseInt(0, 8)?", parseInt(0, 8)); // 0
console.log("parseInt(-0, 8)?", parseInt(-0, 8)); // 0

try
{
	Oo("9"); // throws an InvalidArgumentError.
}
catch(error)
{
	// error.name === "InvalidArgumentError"
	console.error(error.name, error.message);
}
0.0.0

2 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago