https://github.com/swingcosmic/array-proto-ext
A functional extension directly adds to Array.prototype
https://github.com/swingcosmic/array-proto-ext
Last synced: 2 months ago
JSON representation
A functional extension directly adds to Array.prototype
- Host: GitHub
- URL: https://github.com/swingcosmic/array-proto-ext
- Owner: SwingCosmic
- License: mit
- Created: 2019-06-28T14:16:53.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T01:38:27.000Z (over 3 years ago)
- Last Synced: 2023-04-26T03:09:57.844Z (about 3 years ago)
- Language: TypeScript
- Size: 414 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# array-proto-ext
A functional extension directly adds to Array.prototype
* WARNING: Importing this module would modify some properties of `Array.prototype` . Ensure that you know all side effects before import.
----
## features
* Strong type definition
Fully written by TypeScript.
* Webpack support
You can use it in any Webpack project like Vue CLI.
* High performance
* Some functions use the the implementations of `Lodash` .
* Use ES2015 generator function and `for ... of ...` expression(target to ES6) to decrease the useless `for` loop.
* Import just **ONCE** in the entry point
Directly add functions to Array.prototype
* Conditional version of query functions, like `countIf`, `sumBy`, etc.
* Unit test support
----
## example
```javascript
import "array-proto-ext";
let arr = Array.prototype.range(2, 10);
// arr = [2, 3, 4, 5, 6, 7, 8, 9, 10]
let evenCount = arr.countIf(x => x % 2 === 0);
// evenCount = 5
let items = [
{ id: "100001", itemId: 1, name: "item A" },
{ id: "100002", itemId: 2, name: "item B" },
{ id: "100003", itemId: 1, name: "another item A"},
];
let ownedIds = items.distinct(x => x.itemId)
.map(x => x.itemId);
// ownedIds = [1, 2]
```