typed-conversions
Advanced tools
Comparing version 0.10.1 to 0.10.2
@@ -37,5 +37,12 @@ import { IDictionary } from "common-types"; | ||
* @param arr an array of a particular type | ||
* @param keyProperty the property that will be used as the dictionaries key; if false then will assign a firebase pushkey | ||
* @param keyProperty the property that will be used as the dictionaries key; if false | ||
* then will assign a firebase pushkey | ||
<<<<<<< HEAD | ||
* @param removeIdProperty allow you to optionally exclude the `id` from the object | ||
* as it is redundant to the `key` of the hash. By default though, this is _not_ done as | ||
* Firemodel benefits (and expects) from this duplication. | ||
======= | ||
>>>>>>> release/0.10.2 | ||
*/ | ||
export declare function arrayToHash<T = any>(arr: T[], keyProperty?: keyof T | FunctionProperty<T>): IDictionary<T>; | ||
export declare function arrayToHash<T = any>(arr: T[], keyProperty?: keyof T | FunctionProperty<T>, removeIdProperty?: boolean): IDictionary<T>; | ||
/** | ||
@@ -42,0 +49,0 @@ * Snapshot to Array (unordered) |
@@ -65,3 +65,3 @@ "use strict"; | ||
const obj = typeof hash[id] === "object" | ||
? Object.assign({}, hash[id], { [__key__]: id }) : isHashArray | ||
? Object.assign(Object.assign({}, hash[id]), { [__key__]: id }) : isHashArray | ||
? id | ||
@@ -85,5 +85,12 @@ : { [__key__]: id, value: hash[id] }; | ||
* @param arr an array of a particular type | ||
* @param keyProperty the property that will be used as the dictionaries key; if false then will assign a firebase pushkey | ||
* @param keyProperty the property that will be used as the dictionaries key; if false | ||
* then will assign a firebase pushkey | ||
<<<<<<< HEAD | ||
* @param removeIdProperty allow you to optionally exclude the `id` from the object | ||
* as it is redundant to the `key` of the hash. By default though, this is _not_ done as | ||
* Firemodel benefits (and expects) from this duplication. | ||
======= | ||
>>>>>>> release/0.10.2 | ||
*/ | ||
function arrayToHash(arr, keyProperty) { | ||
function arrayToHash(arr, keyProperty, removeIdProperty = false) { | ||
if (arr.length === 0) { | ||
@@ -120,5 +127,5 @@ return {}; | ||
return isScalar | ||
? Object.assign({}, prev, { [key]: true }) : Object.assign({}, prev, { [key]: curr }); | ||
? Object.assign(Object.assign({}, prev), { [key]: true }) : Object.assign(Object.assign({}, prev), { [key]: curr }); | ||
}, {}); | ||
return output; | ||
return removeIdProperty ? removeIdPropertyFromHash(output) : output; | ||
} | ||
@@ -125,0 +132,0 @@ exports.arrayToHash = arrayToHash; |
@@ -37,5 +37,12 @@ import { IDictionary } from "common-types"; | ||
* @param arr an array of a particular type | ||
* @param keyProperty the property that will be used as the dictionaries key; if false then will assign a firebase pushkey | ||
* @param keyProperty the property that will be used as the dictionaries key; if false | ||
* then will assign a firebase pushkey | ||
<<<<<<< HEAD | ||
* @param removeIdProperty allow you to optionally exclude the `id` from the object | ||
* as it is redundant to the `key` of the hash. By default though, this is _not_ done as | ||
* Firemodel benefits (and expects) from this duplication. | ||
======= | ||
>>>>>>> release/0.10.2 | ||
*/ | ||
export declare function arrayToHash<T = any>(arr: T[], keyProperty?: keyof T | FunctionProperty<T>): IDictionary<T>; | ||
export declare function arrayToHash<T = any>(arr: T[], keyProperty?: keyof T | FunctionProperty<T>, removeIdProperty?: boolean): IDictionary<T>; | ||
/** | ||
@@ -42,0 +49,0 @@ * Snapshot to Array (unordered) |
@@ -57,3 +57,3 @@ import get from "get-value"; | ||
const obj = typeof hash[id] === "object" | ||
? Object.assign({}, hash[id], { [__key__]: id }) : isHashArray | ||
? Object.assign(Object.assign({}, hash[id]), { [__key__]: id }) : isHashArray | ||
? id | ||
@@ -75,5 +75,12 @@ : { [__key__]: id, value: hash[id] }; | ||
* @param arr an array of a particular type | ||
* @param keyProperty the property that will be used as the dictionaries key; if false then will assign a firebase pushkey | ||
* @param keyProperty the property that will be used as the dictionaries key; if false | ||
* then will assign a firebase pushkey | ||
<<<<<<< HEAD | ||
* @param removeIdProperty allow you to optionally exclude the `id` from the object | ||
* as it is redundant to the `key` of the hash. By default though, this is _not_ done as | ||
* Firemodel benefits (and expects) from this duplication. | ||
======= | ||
>>>>>>> release/0.10.2 | ||
*/ | ||
export function arrayToHash(arr, keyProperty) { | ||
export function arrayToHash(arr, keyProperty, removeIdProperty = false) { | ||
if (arr.length === 0) { | ||
@@ -110,5 +117,5 @@ return {}; | ||
return isScalar | ||
? Object.assign({}, prev, { [key]: true }) : Object.assign({}, prev, { [key]: curr }); | ||
? Object.assign(Object.assign({}, prev), { [key]: true }) : Object.assign(Object.assign({}, prev), { [key]: curr }); | ||
}, {}); | ||
return output; | ||
return removeIdProperty ? removeIdPropertyFromHash(output) : output; | ||
} | ||
@@ -115,0 +122,0 @@ /** |
{ | ||
"name": "typed-conversions", | ||
"version": "0.10.1", | ||
"version": "0.10.2", | ||
"description": "typed-conversions", | ||
@@ -33,7 +33,7 @@ "license": "MIT", | ||
"dependencies": { | ||
"common-types": "^1.9.7", | ||
"common-types": "^1.12.18", | ||
"get-value": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.1.7", | ||
"@types/chai": "^4.2.9", | ||
"@types/get-value": "^3.0.0", | ||
@@ -46,15 +46,11 @@ "@types/js-yaml": "^3.12.0", | ||
"@types/stack-trace": "^0.0.29", | ||
"bili": "^4.4.0", | ||
"bili": "^4.8.1", | ||
"chai": "^4.2.0", | ||
"coveralls": "^2.0.0", | ||
"firebase-admin": "7.0.0", | ||
"lodash": "^4.17.11", | ||
"mocha": "^6.0.2", | ||
"nyc": "^13.3.0", | ||
"rimraf": "^2.6.3", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-typescript2": "^0.20.0", | ||
"ts-node": "^8.0.3", | ||
"tslint": "^5.13.1", | ||
"typescript": "^3.3.3" | ||
"firebase-admin": "8.9.2", | ||
"lodash": "^4.17.15", | ||
"mocha": "^7.0.1", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^8.6.2", | ||
"tslint": "^5.20.1", | ||
"typescript": "^3.7.5" | ||
}, | ||
@@ -80,2 +76,2 @@ "engines": { | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
46810
17
526
Updatedcommon-types@^1.12.18