@proem/array
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -46,2 +46,40 @@ export function map(array, mapfn) { | ||
}; }; | ||
// Comparison used by newer ES6 operations like Array.include | ||
var sameValueZero = function (x, y) { | ||
return x === y || | ||
(typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); | ||
}; | ||
export function includes(array, item) { | ||
if (array.length === 0) { | ||
return false; | ||
} | ||
for (var i = 0; i < array.length; i++) { | ||
if (sameValueZero(array[i], item)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
export function reverse(array) { | ||
var result = new Array(array.length); | ||
for (var i = 0; i < array.length; i++) { | ||
var target = array.length - i - 1; | ||
result[target] = array[i]; | ||
} | ||
return result; | ||
} | ||
export function range(from, to) { | ||
if (to < from) { | ||
return []; | ||
} | ||
if (from === to) { | ||
return [from]; | ||
} | ||
var result = new Array(to - from); | ||
for (var i = 0; i < to; i++) { | ||
var n = from + i; | ||
result[i] = n; | ||
} | ||
return result; | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -50,2 +50,43 @@ "use strict"; | ||
}; }; | ||
// Comparison used by newer ES6 operations like Array.include | ||
var sameValueZero = function (x, y) { | ||
return x === y || | ||
(typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); | ||
}; | ||
function includes(array, item) { | ||
if (array.length === 0) { | ||
return false; | ||
} | ||
for (var i = 0; i < array.length; i++) { | ||
if (sameValueZero(array[i], item)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
exports.includes = includes; | ||
function reverse(array) { | ||
var result = new Array(array.length); | ||
for (var i = 0; i < array.length; i++) { | ||
var target = array.length - i - 1; | ||
result[target] = array[i]; | ||
} | ||
return result; | ||
} | ||
exports.reverse = reverse; | ||
function range(from, to) { | ||
if (to < from) { | ||
return []; | ||
} | ||
if (from === to) { | ||
return [from]; | ||
} | ||
var result = new Array(to - from); | ||
for (var i = 0; i < to; i++) { | ||
var n = from + i; | ||
result[i] = n; | ||
} | ||
return result; | ||
} | ||
exports.range = range; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@proem/array", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Typescript array utilities", | ||
@@ -16,3 +16,3 @@ "keywords": [ | ||
"module": "esm/index.js", | ||
"types": "lib/index.d.ts", | ||
"types": "types/index.d.ts", | ||
"directories": { | ||
@@ -34,3 +34,3 @@ "lib": "lib" | ||
}, | ||
"gitHead": "3281115642812ee827fb745c38d54da758a82303" | ||
"gitHead": "f01fc3c709e912130aa7de087b76b9ac61d57cce" | ||
} |
@@ -7,6 +7,27 @@ # `@proem/array` | ||
First, import the `@proem/array` module is imported into the namespace | ||
``` | ||
import array from '@proem/array'; | ||
``` | ||
// TODO: DEMONSTRATE API | ||
`@proem/array` provides custom implementations for convenience functions already implemented by the `Array.prototype`, such as the `map` function. The semantics might differ, for example the `array.map` in proem trades the support of sparse arrays for performance. | ||
``` | ||
const input = [1, 2, 3, 4, 5] | ||
const output = array.map(input, n => n + 1) // [2, 3, 4, 5, 6, 7] | ||
``` | ||
Some functions have their partially applicable counterparts. For example, proem provides the `array.map.partial`, which returns a function applicable to arrays. | ||
``` | ||
const a = ["a,", "b", "c"] | ||
const b = ["d", "e", "f"] | ||
const partial = map.partial((str: string) => str.toUpperCase()) | ||
const output = partial(a) // [ 'A,', 'B', 'C' ] | ||
const otherOutput = partial(b) // ['D', 'E', 'F'] | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
173
33
0
14033
7