From 24a85c66373af7749ea2cf5ff733a1cad285f04f Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 2 Jan 2024 17:07:27 +0700 Subject: [PATCH] Meta tweaks --- index.js | 12 ++++++------ package.json | 6 +++++- test.js | 4 ++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index a7ec0d7..5e45aef 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,17 @@ const validate = (name, value) => { if (!Number.isSafeInteger(value)) { - throw new TypeError(`Expected \`${name}\` to be a safe integer`); + throw new TypeError(`Expected \`${name}\` to be a safe integer.`); } }; -const lt = (l, r) => l < r; -const gt = (l, r) => l > r; -const lte = (l, r) => l <= r; -const gte = (l, r) => l >= r; +const lt = (left, right) => left < right; +const gt = (left, right) => left > right; +const lte = (left, right) => left <= right; +const gte = (left, right) => left >= right; export default function * getRange({start = 0, end, step = 1, inclusive = false}) { if (step === 0) { - throw new TypeError('The `step` parameter cannot be zero'); + throw new TypeError('The `step` option cannot be zero.'); } validate('start', start); diff --git a/package.json b/package.json index ff690f3..640adbb 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,11 @@ "url": "https://sindresorhus.com" }, "type": "module", - "exports": "./index.js", + "exports": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "sideEffects": false, "engines": { "node": ">=18" }, diff --git a/test.js b/test.js index 2572735..ec641b1 100644 --- a/test.js +++ b/test.js @@ -16,7 +16,9 @@ test('main', t => { t.deepEqual(get({start: 1, end: 2}), [1]); t.deepEqual(get({start: 1, end: 5}), [1, 2, 3, 4]); t.deepEqual(get({start: -2, end: 2}), [-2, -1, 0, 1]); +}); +test('`step` option', t => { t.deepEqual(get({start: 0, end: 2, step: 2}), [0]); t.deepEqual(get({start: 0, end: 3, step: 2}), [0, 2]); t.deepEqual(get({start: 0, end: 4, step: 2}), [0, 2]); @@ -32,7 +34,9 @@ test('main', t => { t.deepEqual(get({start: 0, end: -3, step: -2}), [0, -2]); t.deepEqual(get({start: 0, end: -4, step: -2}), [0, -2]); t.deepEqual(get({start: 0, end: -6, step: -2}), [0, -2, -4]); +}); +test('`inclusive` option', t => { t.deepEqual(get({end: 0, inclusive: true}), [0]); t.deepEqual(get({end: 1, inclusive: true}), [0, 1]); t.deepEqual(get({end: -2, inclusive: true}), []);