diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..a01f2dcfa2 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +/dist + diff --git a/.gitignore b/.gitignore index ad46b30886..366ec9d174 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ typings/ # next.js build output .next + +# dist +dist/ diff --git a/index-commonjs.js b/index-commonjs.js deleted file mode 100644 index 2ffe66a8c0..0000000000 --- a/index-commonjs.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -// Copyright (C) 2011 Google Inc. -// Copyright (C) 2018 Agoric -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * Is allegedNum a number in the contiguous range of exactly and - * unambiguously representable natural numbers (non-negative integers)? - * - *

See Issue 1801: Nat must include at most (2**53)-1 - * and Allen Wirfs-Brock's suggested phrasing on es-discuss. - */ - -function Nat(allegedNum) { - if (!Number.isSafeInteger(allegedNum)) { - throw new RangeError('not a safe integer'); - } - - if (allegedNum < 0) { - throw new RangeError('negative'); - } - - return allegedNum; -} - -module.exports = Nat; diff --git a/package-lock.json b/package-lock.json index 74c6727ec7..a335f1fabe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -640,6 +640,12 @@ "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", "dev": true }, + "esm": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.7.tgz", + "integrity": "sha512-zsyD5gO8CY9dpK3IrdC4WHtvtHGXEFOpYA4zB+6p+Kygf3vv/6kF3YMEQLOArwKPPNvKt8gjI8UYhQW8bXM/YQ==", + "dev": true + }, "espree": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/espree/-/espree-4.1.0.tgz", diff --git a/package.json b/package.json index f99e7d39f4..5c7018c2f2 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,12 @@ "name": "@agoric/nat", "version": "2.0.0", "description": "Ensures that a number is within the natural numbers (0, 1, 2...) or throws a RangeError", - "main": "index-commonjs.js", - "module": "index.js", + "main": "dist/nat.cjs.js", + "module": "dist/nat.esm.js", + "browser": "dist/nat.umd.js", "scripts": { - "test": "node test/test.js", - "create-cjs": "rollup index.js --file index-commonjs.js --format cjs", + "test": "node -r esm test/test.js", + "build": "rollup -c", "lint-fix": "eslint --fix '**/*.{js,jsx}'", "lint-check": "eslint '**/*.{js,jsx}'" }, @@ -29,6 +30,7 @@ "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" @@ -40,5 +42,8 @@ "integer", "int", "overflow" + ], + "files": [ + "dist" ] } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000000..82c1442fc1 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,20 @@ +export default [ + { + input: 'src/index.js', + output: [ + { + file: 'dist/nat.umd.js', + format: 'umd', + name: 'Nat', + }, + { + file: 'dist/nat.esm.js', + format: 'esm', + }, + { + file: 'dist/nat.cjs.js', + format: 'cjs', + }, + ], + }, +]; diff --git a/index.js b/src/index.js similarity index 100% rename from index.js rename to src/index.js diff --git a/test/test.js b/test/test.js index f5fd9a012a..e375761eb5 100644 --- a/test/test.js +++ b/test/test.js @@ -1,7 +1,7 @@ /* eslint no-mixed-operators: "off" */ -const test = require('tape'); -const Nat = require('../index-commonjs.js'); +import test from 'tape'; +import Nat from '../src/index'; test('Nat() throws when not a natural number', t => { t.equal(Nat(0), 0);