Array and Object Extensions
Negative-index access, aggregation, and existence checks added to Array.prototype and Object.prototype.
Array
Source: src/prototype/Array.ts
| Method / Property | Description |
|---|---|
arr.$sum |
Sum of a numeric array via reduce |
arr.$shuffle |
In-place Fisher–Yates shuffle; returns this |
arr.$map |
A Map of value → index for every entry |
arr._(value, index?) |
Negative-index-aware insert (splice); appends when index is omitted |
arr.$(index) |
Negative-index-aware read |
arr.$i(target) |
indexOf(target), returning undefined instead of -1 |
arr.$_(index) |
Negative-index-aware removal (splice) |
arr.$$(target?) |
true if non-empty (no argument) or if target is present |
arr.$req(body) |
Joins the array as /-separated URL path segments, then calls $req on the resulting path |
Object
Source: src/prototype/Object.ts (extends Object.prototype, so these apply to plain objects)
| Method / Property | Description |
|---|---|
obj.length |
Object.keys(this).length |
obj.$keys / obj.$values |
Object.keys(this) / Object.values(this) |
obj.$map |
Own enumerable entries as a Map |
obj.forEach(cb) |
Array-like iteration: cb(key, value) over own enumerable properties |
obj._(key, value, replace = true) |
Conditional setter — only overwrites an existing key when replace is true |
obj.$$(key?) |
hasOwnProperty(key) if key given, else this.length > 0 |