Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 2, 2024
1 parent 0bbf608 commit 24a85c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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}), []);
Expand Down

0 comments on commit 24a85c6

Please sign in to comment.