New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@agoric/nat

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agoric/nat - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

25

package.json
{
"name": "@agoric/nat",
"version": "2.0.1",
"version": "3.0.0",
"description": "Ensures that a number is within the natural numbers (0, 1, 2...) or throws a RangeError",

@@ -12,3 +12,4 @@ "main": "dist/nat.cjs.js",

"lint-fix": "eslint --fix '**/*.{js,jsx}'",
"lint-check": "eslint '**/*.{js,jsx}'"
"lint-check": "eslint '**/*.{js,jsx}'",
"eslint-disable-stats": "grep -R --exclude-dir=node_modules --include='*.js' 'eslint' . | wc -l | tr -d [:blank:]"
},

@@ -27,13 +28,11 @@ "repository": {

"devDependencies": {
"eslint": "^5.3.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"esm": "^3.2.7",
"prettier": "1.16.4",
"rollup": "^1.1.2",
"tape": "^4.9.2"
"eslint": "^6.7.2",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.1",
"esm": "^3.2.25",
"prettier": "^1.19.1",
"rollup": "^1.27.8",
"tape": "^4.11.0"
},

@@ -40,0 +39,0 @@ "directories": {

@@ -7,6 +7,11 @@ # Nat

`Nat(value)` returns its argument if it represents a non-negative integer (i.e. a "natural number") that can be accurately represented in a JavaScript `Number`, specifically (0, 1, 2... to 2 \*\* 53 - 1). Otherwise it throws a `RangeError` exception. This makes it easy to use on incoming arguments, or as an assertion on generated values.
`Nat(value)` returns its argument if it represents a non-negative
integer (i.e. a "natural number") that can be accurately represented
as a JavaScript
[`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt),
a built-in object that can be used to represent arbitrarily large integers.
If the argument is not a `BigInt` or the argument is negative, an exception is thrown. This makes
it easy to use `Nat()` on incoming arguments, or as an assertion on generated
values.
Traditional JavaScript has a single `Number` type, which is defined to contain a 64-bit IEEE-754 floating point value. This can safely represent a wide range of integers, but if they get too large, `Number` will lose precision: `2**53 + 1` will give you the same value as `2**53 + 2`. In situations where you care about accuracy rather than range, this would be a problem.
You can think of `Nat()` as a type enforcement.

@@ -27,8 +32,2 @@

We also want to use `Nat()` before using values internally, as a precondition check:
```
Nat(ledger.get(purse));
```
Any addition or subtraction expressions dealing with monetary amounts should protected with `Nat()` to guard against overflow/underflow errors. Without this check, the two balances might both be safe, but their sum might be too large to represent accurately, causing precision errors in subsequent computation:

@@ -43,3 +42,3 @@

Array indexes can be wrapped with `Nat()`, to guard against the surprising string coersion of non-integral index values:
Array indexes can be wrapped with `Nat()`, to guard against the surprising string coercion of non-integral index values:

@@ -59,12 +58,4 @@ ```

By excluding 2^53, we have the nice invariant that if
Because `Nat` uses JavaScript's upcoming [`BigInt` standard](https://tc39.github.io/proposal-bigint/), the range of accurately-representable integers is effectively unbounded.
`Nat(a)`,
`Nat(b)`,
`Nat(a+b)`,
are all true, then `(a+b)` is an accurate sum of a and b.
Future versions of `Nat` will use JavaScript's upcoming [`BigInt` standard](https://tc39.github.io/proposal-bigint/), to increase the range of accurately-representable integers to be effectively unbounded.
## History

@@ -71,0 +62,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc