range-pie 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -70
- package/dist/py-range.d.ts +7 -5
- package/dist/py-range.js +4 -4
- package/package.json +21 -16
package/README.md
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
A TypeScript/JavaScript library that brings Python's range functionality to JavaScript, enhanced with familiar array methods. This lightweight utility provides a seamless way to work with numeric sequences while maintaining JavaScript's functional programming paradigm. Fully typed for TypeScript users while remaining compatible with JavaScript projects.
|
|
4
4
|
|
|
5
|
+
[](https://www.npmjs.com/package/range-pie)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
5
8
|
## Table of Contents
|
|
6
9
|
|
|
7
10
|
- [Installation](#installation)
|
|
8
11
|
- [Basic Usage](#basic-usage)
|
|
9
|
-
|
|
10
12
|
- [JavaScript](#javascript)
|
|
11
13
|
- [TypeScript](#typescript)
|
|
12
14
|
|
|
13
15
|
- [API Reference](#api-reference)
|
|
14
|
-
|
|
15
16
|
- [Constructor Options](#constructor-options)
|
|
16
17
|
- [Properties](#properties)
|
|
17
18
|
- [at()](#at)
|
|
@@ -37,12 +38,10 @@ A TypeScript/JavaScript library that brings Python's range functionality to Java
|
|
|
37
38
|
- [values()](#values)
|
|
38
39
|
|
|
39
40
|
- [Advanced Usage](#advanced-usage)
|
|
40
|
-
|
|
41
41
|
- [Iteration](#iteration)
|
|
42
42
|
- [Proxy Access](#proxy-access)
|
|
43
43
|
|
|
44
44
|
- [Examples](#examples)
|
|
45
|
-
|
|
46
45
|
- [Methods chaining](#methods-chaining)
|
|
47
46
|
- [Using as Array-like Object](#using-as-array-like-object)
|
|
48
47
|
- [Example Files](#example-files)
|
|
@@ -62,9 +61,9 @@ npm install range-pie
|
|
|
62
61
|
|
|
63
62
|
```javascript
|
|
64
63
|
// CommonJS - Both import styles are supported
|
|
65
|
-
const { PyRange } = require(
|
|
64
|
+
const { PyRange } = require("range-pie"); // Named import style
|
|
66
65
|
// OR
|
|
67
|
-
const PyRange = require(
|
|
66
|
+
const PyRange = require("range-pie"); // Default import style
|
|
68
67
|
|
|
69
68
|
// Create a range from 0 to 5
|
|
70
69
|
const range = new PyRange(5);
|
|
@@ -87,20 +86,20 @@ console.log([...range4]); // [5, 4, 3]
|
|
|
87
86
|
|
|
88
87
|
```typescript
|
|
89
88
|
// ES Modules - Both import styles are supported
|
|
90
|
-
import { PyRange } from
|
|
89
|
+
import { PyRange } from "range-pie"; // Named import style
|
|
91
90
|
// OR
|
|
92
|
-
import PyRange from
|
|
91
|
+
import PyRange from "range-pie"; // Default import style
|
|
93
92
|
|
|
94
93
|
// Create a range from 0 to 5
|
|
95
94
|
const range = new PyRange(5);
|
|
96
95
|
console.log([...range]); // [0, 1, 2, 3, 4]
|
|
97
96
|
|
|
98
97
|
// Type-safe operations
|
|
99
|
-
const doubledValues: number[] = range.map(x => x * 2);
|
|
98
|
+
const doubledValues: number[] = range.map((x) => x * 2);
|
|
100
99
|
console.log(doubledValues); // [0, 2, 4, 6, 8]
|
|
101
100
|
|
|
102
101
|
// Type inference works with generics
|
|
103
|
-
const stringValues: string[] = range.map(x => `Value: ${x}`);
|
|
102
|
+
const stringValues: string[] = range.map((x) => `Value: ${x}`);
|
|
104
103
|
console.log(stringValues); // ['Value: 0', 'Value: 1', 'Value: 2', 'Value: 3', 'Value: 4']
|
|
105
104
|
```
|
|
106
105
|
|
|
@@ -109,9 +108,9 @@ console.log(stringValues); // ['Value: 0', 'Value: 1', 'Value: 2', 'Value: 3', '
|
|
|
109
108
|
### Constructor Options
|
|
110
109
|
|
|
111
110
|
```javascript
|
|
112
|
-
new PyRange(stop)
|
|
113
|
-
new PyRange(start, stop)
|
|
114
|
-
new PyRange(start, stop, step)
|
|
111
|
+
new PyRange(stop); // 0 to stop-1
|
|
112
|
+
new PyRange(start, stop); // start to stop-1
|
|
113
|
+
new PyRange(start, stop, step); // start to stop-1 with step
|
|
115
114
|
```
|
|
116
115
|
|
|
117
116
|
- **PyRange(stop:number)**
|
|
@@ -148,9 +147,9 @@ console.log(PyRange(2, -10, -1));
|
|
|
148
147
|
|
|
149
148
|
```javascript
|
|
150
149
|
const range = new PyRange(1, 10, 2);
|
|
151
|
-
console.log(range.start);
|
|
152
|
-
console.log(range.stop);
|
|
153
|
-
console.log(range.step);
|
|
150
|
+
console.log(range.start); // 1
|
|
151
|
+
console.log(range.stop); // 10
|
|
152
|
+
console.log(range.step); // 2
|
|
154
153
|
console.log(range.length); // 5
|
|
155
154
|
```
|
|
156
155
|
|
|
@@ -159,9 +158,9 @@ console.log(range.length); // 5
|
|
|
159
158
|
The 'at' method accepts a number as argument to gets the value at the specified index in a range. Generate a RangeError if the index is out of range.
|
|
160
159
|
|
|
161
160
|
```javascript
|
|
162
|
-
const range = new PyRange(1, 5);
|
|
163
|
-
console.log(range.at(0));
|
|
164
|
-
console.log(range.at(2));
|
|
161
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
162
|
+
console.log(range.at(0)); // 1
|
|
163
|
+
console.log(range.at(2)); // 3
|
|
165
164
|
console.log(range.at(-1)); // RangeError
|
|
166
165
|
```
|
|
167
166
|
|
|
@@ -188,8 +187,8 @@ console.log(range.toArray()); // [1, 2, 3]
|
|
|
188
187
|
It works the same as [**`Array.prototype.map`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
|
|
189
188
|
|
|
190
189
|
```javascript
|
|
191
|
-
const range = new PyRange(1, 4);
|
|
192
|
-
console.log(range.map(x => x * 2));
|
|
190
|
+
const range = new PyRange(1, 4); // [1, 2, 3]
|
|
191
|
+
console.log(range.map((x) => x * 2)); // [2, 4, 6]
|
|
193
192
|
```
|
|
194
193
|
|
|
195
194
|
### filter()
|
|
@@ -197,8 +196,8 @@ console.log(range.map(x => x * 2)); // [2, 4, 6]
|
|
|
197
196
|
It works the same as [**`Array.prototype.filter`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
|
|
198
197
|
|
|
199
198
|
```javascript
|
|
200
|
-
const range = new PyRange(1, 6);
|
|
201
|
-
console.log(range.filter(x => x % 2 === 0));
|
|
199
|
+
const range = new PyRange(1, 6); // [1, 2, 3, 4, 5]
|
|
200
|
+
console.log(range.filter((x) => x % 2 === 0)); // [2, 4]
|
|
202
201
|
```
|
|
203
202
|
|
|
204
203
|
### reduce()
|
|
@@ -206,9 +205,9 @@ console.log(range.filter(x => x % 2 === 0)); // [2, 4]
|
|
|
206
205
|
It works the same as [**`Array.prototype.reduce`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)
|
|
207
206
|
|
|
208
207
|
```javascript
|
|
209
|
-
const range = new PyRange(1, 4);
|
|
208
|
+
const range = new PyRange(1, 4); // [1, 2, 3]
|
|
210
209
|
const sum = range.reduce((acc, curr) => acc + curr, 0);
|
|
211
|
-
console.log(sum);
|
|
210
|
+
console.log(sum); // 6
|
|
212
211
|
```
|
|
213
212
|
|
|
214
213
|
### some()
|
|
@@ -216,9 +215,9 @@ console.log(sum); // 6
|
|
|
216
215
|
It works the same as [**`Array.prototype.some`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
|
|
217
216
|
|
|
218
217
|
```javascript
|
|
219
|
-
const range = new PyRange(1, 5);
|
|
220
|
-
console.log(range.some(x => x > 3));
|
|
221
|
-
console.log(range.some(x => x < 0));
|
|
218
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
219
|
+
console.log(range.some((x) => x > 3)); // true
|
|
220
|
+
console.log(range.some((x) => x < 0)); // false
|
|
222
221
|
```
|
|
223
222
|
|
|
224
223
|
### every()
|
|
@@ -226,9 +225,9 @@ console.log(range.some(x => x < 0)); // false
|
|
|
226
225
|
It works the same as [**`Array.prototype.every`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
|
|
227
226
|
|
|
228
227
|
```javascript
|
|
229
|
-
const range = new PyRange(1, 5);
|
|
230
|
-
console.log(range.every(x => x > 0));
|
|
231
|
-
console.log(range.every(x => x > 2));
|
|
228
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
229
|
+
console.log(range.every((x) => x > 0)); // true
|
|
230
|
+
console.log(range.every((x) => x > 2)); // false
|
|
232
231
|
```
|
|
233
232
|
|
|
234
233
|
### find()
|
|
@@ -236,9 +235,9 @@ console.log(range.every(x => x > 2)); // false
|
|
|
236
235
|
It works the same as [**`Array.prototype.find`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
|
|
237
236
|
|
|
238
237
|
```javascript
|
|
239
|
-
const range = new PyRange(1, 5);
|
|
240
|
-
console.log(range.find(x => x > 2));
|
|
241
|
-
console.log(range.find(x => x > 5));
|
|
238
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
239
|
+
console.log(range.find((x) => x > 2)); // 3
|
|
240
|
+
console.log(range.find((x) => x > 5)); // undefined
|
|
242
241
|
```
|
|
243
242
|
|
|
244
243
|
### findIndex()
|
|
@@ -246,9 +245,9 @@ console.log(range.find(x => x > 5)); // undefined
|
|
|
246
245
|
It works the same as [**`Array.prototype.findIndex`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
|
|
247
246
|
|
|
248
247
|
```javascript
|
|
249
|
-
const range = new PyRange(1, 5);
|
|
250
|
-
console.log(range.findIndex(x => x > 2));
|
|
251
|
-
console.log(range.findIndex(x => x > 5));
|
|
248
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
249
|
+
console.log(range.findIndex((x) => x > 2)); // 2
|
|
250
|
+
console.log(range.findIndex((x) => x > 5)); // -1
|
|
252
251
|
```
|
|
253
252
|
|
|
254
253
|
### findLastIndex()
|
|
@@ -256,9 +255,9 @@ console.log(range.findIndex(x => x > 5)); // -1
|
|
|
256
255
|
It works the same as [**`Array.prototype.findLastIndex`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
|
|
257
256
|
|
|
258
257
|
```javascript
|
|
259
|
-
const range = new PyRange(1, 5);
|
|
260
|
-
console.log(range.findLastIndex(x => x > 2));
|
|
261
|
-
console.log(range.findLastIndex(x => x > 5));
|
|
258
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
259
|
+
console.log(range.findLastIndex((x) => x > 2)); // 3
|
|
260
|
+
console.log(range.findLastIndex((x) => x > 5)); // -1
|
|
262
261
|
```
|
|
263
262
|
|
|
264
263
|
### forEach()
|
|
@@ -266,8 +265,8 @@ console.log(range.findLastIndex(x => x > 5)); // -1
|
|
|
266
265
|
It works the same as [**`Array.prototype.forEach`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
|
|
267
266
|
|
|
268
267
|
```javascript
|
|
269
|
-
const range = new PyRange(1, 4);
|
|
270
|
-
range.forEach(x => console.log(x));
|
|
268
|
+
const range = new PyRange(1, 4); // [1, 2, 3]
|
|
269
|
+
range.forEach((x) => console.log(x));
|
|
271
270
|
// 1
|
|
272
271
|
// 2
|
|
273
272
|
// 3
|
|
@@ -278,9 +277,9 @@ range.forEach(x => console.log(x));
|
|
|
278
277
|
It works the same as [**`Array.prototype.includes`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
|
|
279
278
|
|
|
280
279
|
```javascript
|
|
281
|
-
const range = new PyRange(1, 5);
|
|
282
|
-
console.log(range.includes(3));
|
|
283
|
-
console.log(range.includes(5));
|
|
280
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
281
|
+
console.log(range.includes(3)); // true
|
|
282
|
+
console.log(range.includes(5)); // false
|
|
284
283
|
```
|
|
285
284
|
|
|
286
285
|
### indexOf()
|
|
@@ -288,9 +287,9 @@ console.log(range.includes(5)); // false
|
|
|
288
287
|
It works the same as [**`Array.prototype.indexOf`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
|
|
289
288
|
|
|
290
289
|
```javascript
|
|
291
|
-
const range = new PyRange(1, 5);
|
|
292
|
-
console.log(range.indexOf(3));
|
|
293
|
-
console.log(range.indexOf(5));
|
|
290
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
291
|
+
console.log(range.indexOf(3)); // 2
|
|
292
|
+
console.log(range.indexOf(5)); // -1
|
|
294
293
|
```
|
|
295
294
|
|
|
296
295
|
### lastIndexOf()
|
|
@@ -298,9 +297,9 @@ console.log(range.indexOf(5)); // -1
|
|
|
298
297
|
It works the same as [**`Array.prototype.lastIndexOf`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
|
|
299
298
|
|
|
300
299
|
```javascript
|
|
301
|
-
const range = new PyRange(1, 5, 1);
|
|
302
|
-
console.log(range.lastIndexOf(3));
|
|
303
|
-
console.log(range.lastIndexOf(5));
|
|
300
|
+
const range = new PyRange(1, 5, 1); // [1, 2, 3, 4]
|
|
301
|
+
console.log(range.lastIndexOf(3)); // 2
|
|
302
|
+
console.log(range.lastIndexOf(5)); // -1
|
|
304
303
|
```
|
|
305
304
|
|
|
306
305
|
### pop()
|
|
@@ -310,9 +309,9 @@ this method removes the last value from the range, shortens the range and
|
|
|
310
309
|
returns that value.
|
|
311
310
|
|
|
312
311
|
```javascript
|
|
313
|
-
const range = new PyRange(1, 5);
|
|
314
|
-
console.log(range.pop());
|
|
315
|
-
console.log([...range]);
|
|
312
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
313
|
+
console.log(range.pop()); // 4
|
|
314
|
+
console.log([...range]); // [1, 2, 3]
|
|
316
315
|
```
|
|
317
316
|
|
|
318
317
|
### slice()
|
|
@@ -322,10 +321,10 @@ It returns a new PyRange instance containing elements from the specified indices
|
|
|
322
321
|
The original range is not modified.
|
|
323
322
|
|
|
324
323
|
```javascript
|
|
325
|
-
const range = new PyRange(0, 10);
|
|
324
|
+
const range = new PyRange(0, 10); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
326
325
|
const sliced = range.slice(2, 5);
|
|
327
326
|
console.log([...sliced]); // [2, 3, 4]
|
|
328
|
-
console.log([...range]);
|
|
327
|
+
console.log([...range]); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] (unchanged)
|
|
329
328
|
|
|
330
329
|
// Negative indices are supported
|
|
331
330
|
const lastThree = range.slice(-3);
|
|
@@ -337,13 +336,13 @@ console.log([...lastThree]); // [7, 8, 9]
|
|
|
337
336
|
It works the same as [**`Array.prototype.reverse`**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
|
|
338
337
|
|
|
339
338
|
```javascript
|
|
340
|
-
const range = new PyRange(1, 5);
|
|
341
|
-
console.log([...range]);
|
|
339
|
+
const range = new PyRange(1, 5); // [1, 2, 3, 4]
|
|
340
|
+
console.log([...range]); // [1, 2, 3, 4]
|
|
342
341
|
|
|
343
342
|
const reversed = range.reverse(); // [4, 3, 2, 1]
|
|
344
|
-
console.log([...reversed]);
|
|
343
|
+
console.log([...reversed]); // [4, 3, 2, 1]
|
|
345
344
|
|
|
346
|
-
const rangeWithStep = new PyRange(1, 10, 2);
|
|
345
|
+
const rangeWithStep = new PyRange(1, 10, 2); // [1, 3, 5, 7, 9]
|
|
347
346
|
const reversedStep = rangeWithStep.reverse(); // [9, 7, 5, 3, 1]
|
|
348
347
|
console.log([...reversedStep]);
|
|
349
348
|
```
|
|
@@ -354,7 +353,7 @@ It works the same as [**`Array.prototype.entries`**](https://developer.mozilla.o
|
|
|
354
353
|
It returns an iterator of `[index, value]` pairs.
|
|
355
354
|
|
|
356
355
|
```javascript
|
|
357
|
-
const range = new PyRange(1, 4);
|
|
356
|
+
const range = new PyRange(1, 4); // [1, 2, 3]
|
|
358
357
|
for (const [index, value] of range.entries()) {
|
|
359
358
|
console.log(index, value);
|
|
360
359
|
}
|
|
@@ -369,7 +368,7 @@ It works the same as [**`Array.prototype.keys`**](https://developer.mozilla.org/
|
|
|
369
368
|
It returns an iterator of the indices of the range.
|
|
370
369
|
|
|
371
370
|
```javascript
|
|
372
|
-
const range = new PyRange(3);
|
|
371
|
+
const range = new PyRange(3); // [0, 1, 2]
|
|
373
372
|
console.log([...range.keys()]); // [0, 1, 2]
|
|
374
373
|
```
|
|
375
374
|
|
|
@@ -379,7 +378,7 @@ It works the same as [**`Array.prototype.values`**](https://developer.mozilla.or
|
|
|
379
378
|
It returns an iterator of the values in the range.
|
|
380
379
|
|
|
381
380
|
```javascript
|
|
382
|
-
const range = new PyRange(3);
|
|
381
|
+
const range = new PyRange(3); // [0, 1, 2]
|
|
383
382
|
console.log([...range.values()]); // [0, 1, 2]
|
|
384
383
|
```
|
|
385
384
|
|
|
@@ -392,7 +391,7 @@ const range = new PyRange(3);
|
|
|
392
391
|
|
|
393
392
|
// For...of loop
|
|
394
393
|
for (const num of range) {
|
|
395
|
-
|
|
394
|
+
console.log(num); // 0, 1, 2
|
|
396
395
|
}
|
|
397
396
|
|
|
398
397
|
// Spread operator
|
|
@@ -425,13 +424,13 @@ This package is written in TypeScript and provides full type definitions for all
|
|
|
425
424
|
const range = new PyRange(5);
|
|
426
425
|
|
|
427
426
|
// TypeScript knows this is a number[]
|
|
428
|
-
const numbers = range.map(x => x * 2);
|
|
427
|
+
const numbers = range.map((x) => x * 2);
|
|
429
428
|
|
|
430
429
|
// TypeScript knows this is a string[]
|
|
431
|
-
const strings = range.map(x => `Number: ${x}`);
|
|
430
|
+
const strings = range.map((x) => `Number: ${x}`);
|
|
432
431
|
|
|
433
432
|
// TypeScript knows this is a boolean[]
|
|
434
|
-
const booleans = range.map(x => x % 2 === 0);
|
|
433
|
+
const booleans = range.map((x) => x % 2 === 0);
|
|
435
434
|
```
|
|
436
435
|
|
|
437
436
|
## Examples
|
|
@@ -440,9 +439,7 @@ const booleans = range.map(x => x % 2 === 0);
|
|
|
440
439
|
|
|
441
440
|
```javascript
|
|
442
441
|
const range = new PyRange(1, 6);
|
|
443
|
-
const squares = range
|
|
444
|
-
.filter(x => x % 2 === 0)
|
|
445
|
-
.map(x => x * x);
|
|
442
|
+
const squares = range.filter((x) => x % 2 === 0).map((x) => x * x);
|
|
446
443
|
console.log(squares); // [4, 16]
|
|
447
444
|
```
|
|
448
445
|
|
package/dist/py-range.d.ts
CHANGED
|
@@ -149,19 +149,19 @@ declare class PyRange implements Iterable<number> {
|
|
|
149
149
|
* @param {any} value - The value to search for.
|
|
150
150
|
* @returns {boolean} True if the value is present, false otherwise.
|
|
151
151
|
*/
|
|
152
|
-
includes(value:
|
|
152
|
+
includes(value: unknown): boolean;
|
|
153
153
|
/**
|
|
154
154
|
* Returns the index of the first occurrence of the specified value, or -1 if it is not present.
|
|
155
155
|
* @param {any} value - The value to search for.
|
|
156
156
|
* @returns {number} The index of the value, or -1 if it is not present.
|
|
157
157
|
*/
|
|
158
|
-
indexOf(value:
|
|
158
|
+
indexOf(value: unknown): number;
|
|
159
159
|
/**
|
|
160
160
|
* Returns the index of the last occurrence of the specified value, or -1 if it is not present.
|
|
161
161
|
* @param {any} value - The value to search for.
|
|
162
162
|
* @returns {number} The index of the last occurrence of the value, or -1 if it is not present.
|
|
163
163
|
*/
|
|
164
|
-
lastIndexOf(value:
|
|
164
|
+
lastIndexOf(value: unknown): number;
|
|
165
165
|
/**
|
|
166
166
|
* Removes the last element from the range and returns it.
|
|
167
167
|
*
|
|
@@ -227,9 +227,11 @@ declare class PyRange implements Iterable<number> {
|
|
|
227
227
|
* This proxy enables accessing range elements via array-like indexing.
|
|
228
228
|
* If the property is a number, it will return the element at that index.
|
|
229
229
|
*
|
|
230
|
-
* @returns {
|
|
230
|
+
* @returns {PyRange & { [key: number]: number }} A proxy for the PyRange instance.
|
|
231
231
|
*/
|
|
232
|
-
asProxy():
|
|
232
|
+
asProxy(): PyRange & {
|
|
233
|
+
[key: number]: number;
|
|
234
|
+
};
|
|
233
235
|
}
|
|
234
236
|
export { PyRange };
|
|
235
237
|
export default PyRange;
|
package/dist/py-range.js
CHANGED
|
@@ -443,18 +443,18 @@ class PyRange {
|
|
|
443
443
|
* This proxy enables accessing range elements via array-like indexing.
|
|
444
444
|
* If the property is a number, it will return the element at that index.
|
|
445
445
|
*
|
|
446
|
-
* @returns {
|
|
446
|
+
* @returns {PyRange & { [key: number]: number }} A proxy for the PyRange instance.
|
|
447
447
|
*/
|
|
448
448
|
asProxy() {
|
|
449
449
|
return new Proxy(this, {
|
|
450
|
-
get(target, prop) {
|
|
450
|
+
get(target, prop, receiver) {
|
|
451
451
|
if (typeof prop === "symbol") {
|
|
452
|
-
return target
|
|
452
|
+
return Reflect.get(target, prop, receiver);
|
|
453
453
|
}
|
|
454
454
|
if (!isNaN(Number(prop))) {
|
|
455
455
|
return target.at(parseInt(String(prop), 10));
|
|
456
456
|
}
|
|
457
|
-
return target
|
|
457
|
+
return Reflect.get(target, prop, receiver);
|
|
458
458
|
},
|
|
459
459
|
});
|
|
460
460
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "range-pie",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "A TypeScript class that simulates Python's range function, combined with several useful JavaScript array methods.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -22,22 +22,25 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsc",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
25
26
|
"build:prod": "tsc -p tsconfig.prod.json",
|
|
26
27
|
"build:watch": "tsc --watch",
|
|
28
|
+
"prepare": "husky",
|
|
27
29
|
"prepublishOnly": "npm run build:prod && npm run test",
|
|
28
30
|
"test": "jest",
|
|
29
31
|
"lint": "eslint . --ext .ts,.js",
|
|
30
32
|
"lint:fix": "eslint . --ext .ts,.js --fix",
|
|
31
33
|
"test:watch": "jest --watch",
|
|
32
34
|
"clean": "rimraf dist",
|
|
33
|
-
"format": "prettier --write \"src/**/*.{ts,js}\" \"test/**/*.{ts,js}\" \"examples/**/*.{ts,js}\" \"
|
|
34
|
-
"format:check": "prettier --check \"src/**/*.{ts,js}\" \"test/**/*.{ts,js}\" \"examples/**/*.{ts,js}\" \"
|
|
35
|
+
"format": "prettier --write \"src/**/*.{ts,js}\" \"test/**/*.{ts,js}\" \"examples/**/*.{ts,js}\" \"*.{js,json}\"",
|
|
36
|
+
"format:check": "prettier --check \"src/**/*.{ts,js}\" \"test/**/*.{ts,js}\" \"examples/**/*.{ts,js}\" \"*.{js,json}\"",
|
|
35
37
|
"example:basic": "node examples/basic-usage.js",
|
|
36
38
|
"example:array": "node examples/array-methods.js",
|
|
37
39
|
"example:advanced": "node examples/advanced-usage.js",
|
|
38
40
|
"example:ts": "ts-node examples/typescript-usage.ts",
|
|
39
41
|
"example:methods": "for file in examples/methods/*.ts; do echo \"\\n=== Running $file ===\"; ts-node \"$file\"; done",
|
|
40
|
-
"knip": "knip"
|
|
42
|
+
"knip": "knip",
|
|
43
|
+
"precommit": "npm run typecheck && npx --no-install lint-staged"
|
|
41
44
|
},
|
|
42
45
|
"keywords": [
|
|
43
46
|
"range",
|
|
@@ -57,18 +60,20 @@
|
|
|
57
60
|
"url": "git+https://github.com/SkorpionG/range-pie.git"
|
|
58
61
|
},
|
|
59
62
|
"devDependencies": {
|
|
60
|
-
"@eslint/js": "^9.
|
|
61
|
-
"@types/jest": "^
|
|
62
|
-
"@types/node": "^
|
|
63
|
-
"eslint": "^9.
|
|
64
|
-
"globals": "^
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
63
|
+
"@eslint/js": "^9.39.4",
|
|
64
|
+
"@types/jest": "^30.0.0",
|
|
65
|
+
"@types/node": "^25.4.0",
|
|
66
|
+
"eslint": "^9.39.4",
|
|
67
|
+
"globals": "^17.4.0",
|
|
68
|
+
"husky": "^9.1.7",
|
|
69
|
+
"jest": "^30.3.0",
|
|
70
|
+
"knip": "^5.86.0",
|
|
71
|
+
"lint-staged": "^16.3.3",
|
|
72
|
+
"prettier": "^3.8.1",
|
|
73
|
+
"rimraf": "^6.1.3",
|
|
74
|
+
"ts-jest": "^29.4.6",
|
|
70
75
|
"ts-node": "^10.9.1",
|
|
71
|
-
"typescript": "^5.
|
|
72
|
-
"typescript-eslint": "^8.
|
|
76
|
+
"typescript": "^5.9.3",
|
|
77
|
+
"typescript-eslint": "^8.57.0"
|
|
73
78
|
}
|
|
74
79
|
}
|