@daeinc/array
Advanced tools
Comparing version 0.3.4 to 0.4.0
@@ -71,2 +71,11 @@ /** | ||
/** | ||
* convert object key:value pairs into simple array of values | ||
* @param obj | ||
* @param keys array of string keys. order is preserved. | ||
* @returns | ||
*/ | ||
export declare const objectToArray: <T>(obj: { | ||
[key: string]: T; | ||
}, keys: string[]) => T[]; | ||
/** | ||
* helper function to get object values inside an array. all objects must have same keys present. | ||
@@ -73,0 +82,0 @@ * |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unwrapArrayOfObjects = exports.isAnyZero = exports.isAnyOne = exports.isAllZero = exports.isAllOne = exports.interpolateArray = exports.getNonZeroIndices = exports.fillAndMap = exports.addToArray = exports.accumulate = void 0; | ||
exports.unwrapArrayOfObjects = exports.objectToArray = exports.isAnyZero = exports.isAnyOne = exports.isAllZero = exports.isAllOne = exports.interpolateArray = exports.getNonZeroIndices = exports.fillAndMap = exports.addToArray = exports.accumulate = void 0; | ||
const math_1 = require("@daeinc/math"); | ||
@@ -128,2 +128,12 @@ /** | ||
/** | ||
* convert object key:value pairs into simple array of values | ||
* @param obj | ||
* @param keys array of string keys. order is preserved. | ||
* @returns | ||
*/ | ||
const objectToArray = (obj, keys) => { | ||
return keys.map((key) => obj[key]); | ||
}; | ||
exports.objectToArray = objectToArray; | ||
/** | ||
* helper function to get object values inside an array. all objects must have same keys present. | ||
@@ -130,0 +140,0 @@ * |
{ | ||
"name": "@daeinc/array", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"description": "Array utilities", | ||
@@ -5,0 +5,0 @@ "types": "./dist/index.d.ts", |
@@ -19,7 +19,12 @@ # @daeinc/array | ||
### accumulate | ||
```ts | ||
const accumulate: (arr: number[], precision?: number) => number[]; | ||
``` | ||
Takes in a number array and returns a new array with values accumulated. For example, the input array `[1, 2, 3, 4]` will return `[1, 3, 6, 10]`. It also takes an optional parameter `precision`(default=4) to compensate for float rounding error. The original values are used while summing, but the return values will be rounded. | ||
### addToArray | ||
```ts | ||
@@ -33,14 +38,23 @@ const addToArray: <T>( | ||
``` | ||
Adds a new element to array in-place while limiting how many to keep history. The mode `first` will insert at the beginning of the array. | ||
### fillAndMap | ||
```ts | ||
const fillAndMap: <T>(n: number, fn: (el: null, idx: number) => T) => T[]; | ||
``` | ||
Creates a new array with given length and maps values | ||
### getNonZeroIndices | ||
```ts | ||
const getNonZeroIndices: (arr: number[]) => number[]; | ||
``` | ||
Check for elements with non-zero values and return indices. | ||
### interpolateArray | ||
```ts | ||
@@ -53,25 +67,53 @@ const interpolateArray: ( | ||
``` | ||
Interpolates between two 1-dimensional arrays of same size. | ||
### isAllOne | ||
```ts | ||
const isAllOne: (arr: number[]) => boolean; | ||
``` | ||
Returns `true` if all elements of input array is `1`. | ||
### isAllZero | ||
```ts | ||
const isAllZero: (arr: number[]) => boolean; | ||
``` | ||
Returns `true` if all elements of input array is `0`. | ||
### isAnyOne | ||
```ts | ||
const isAnyOne: (arr: number[]) => boolean; | ||
``` | ||
Returns `true` if any element of input array is `1`. | ||
### isAnyZero | ||
```ts | ||
const isAnyZero: (arr: number[]) => boolean; | ||
``` | ||
Returns `true` if any element of input array is `0`. | ||
### objectToArray | ||
```ts | ||
const objectToArray: <T>( | ||
obj: { | ||
[key: string]: T; | ||
}, | ||
keys: string[] | ||
) => T[]; | ||
``` | ||
Convert object key-value pairs into simple array of values. Only included keys will be converted. The order is preserved. | ||
### unwrapArrayOfObjects | ||
```ts | ||
const unwrapArrayOfObjects: ( | ||
@@ -84,2 +126,3 @@ arr: { | ||
``` | ||
A helper function to get object values inside an array. All objects must have same keys present. For example, when the input array is `[ {name: val1}, {name: val2} ]`, calling `unwrapArrayOfObjects(arr, "name")` will return `[val1, val2]`. | ||
@@ -86,0 +129,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16767
246
133