typed-conversions
Advanced tools
Comparing version 0.8.6 to 0.8.7
@@ -54,7 +54,12 @@ function _typeof(obj) { | ||
function keyValueDictionaryToArray(dict) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var __key__ = options.key || "key"; | ||
var __value__ = options.value || "value"; | ||
return Object.keys(dict).reduce(function (result, key) { | ||
return result.concat({ | ||
key: key, | ||
value: dict[key] | ||
}); | ||
var _result$concat; | ||
return result.concat((_result$concat = {}, _defineProperty(_result$concat, __key__, key), _defineProperty(_result$concat, __value__, dict[key]), _result$concat)); | ||
}, []); | ||
@@ -61,0 +66,0 @@ } |
@@ -1,2 +0,2 @@ | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()}(0,function(){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(e)}function e(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("lodash.get");function o(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id";if(t&&"object"!==r(t))throw new Error("Cant convert hash-to-array because hash was not passed in: "+t);var n=Object.assign({},t),a=[];return Object.keys(n).forEach(function(r){var t=n[r],i=!!Object.keys(t).reduce(function(r,e){return!0===t[e]&&r},!0),s=Object.keys(t).every(function(r){return!0===n[r]});i?s?a.push(r):a.push(Object.assign(e({},o,r),{value:n[r]})):a.push(i?r:Object.assign({},t,e({},o,r)))}),a}exports.removeIdPropertyFromHash=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id",t={};return Object.keys(r).map(function(o){var n=r[o];t[o]={},Object.keys(n).map(function(r){r!==e&&(t[o][r]=n[r])})}),t},exports.keyValueDictionaryToArray=function(r){return Object.keys(r).reduce(function(e,t){return e.concat({key:t,value:r[t]})},[])},exports.hashToArray=o,exports.flatten=function r(e){return e.reduce(function(e,t){return e.concat(Array.isArray(t)?r(t):t)},[])},exports.arrayToHash=function(t,o){if(0===t.length)return{};var n="object"!==r(t[0]);if(n&&o){var a=new Error("You can not have an array of primitive values AND set a keyProperty!");throw a.name="NotAllowed",a}if(!o&&!n){if(!t[0].hasOwnProperty("id")){var i=new Error('Tried to default to a keyProperty of "id" but that property does not appear to be in the array passed in');throw i.name="NotAllowed",i}o="id"}if(!Array.isArray(t)){var s=new Error("arrayToHash: input was not an array!");throw s.name="NotAllowed",s}return t.reduce(function(r,t){var a=n?t:t[o];return n?Object.assign({},r,e({},a,!0)):Object.assign({},r,e({},a,t))},{})},exports.snapshotToArray=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id";return o(r.val()||{},e)},exports.snapshotToHash=function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id",n=t.val()||{};return Object.keys(n).forEach(function(t){var a;return"object"===r(n[t])?n[t][o]=t:n[t]=(e(a={},o,t),e(a,"value",n[t]),a)}),n},exports.snapshotToOrderedArray=function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id",n=[];return t.forEach(function(t){var a=t.val(),i=t.key;if("object"!==r(a))throw new Error("Can't create a list from scalar values: \"".concat(a,'" | "').concat(i,'"'));return n.push(Object.assign(e({},o,i),a)),!0}),n},exports.snapshotToOrderedHash=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id",t=this.snapshotToOrderedArray(r,e);return this.arrayToHash(t)},exports.getPropertyAcrossDictionaryItems=function(r,e){var o=[];return Object.keys(r).map(function(n){var a=t(r[n],e,void 0);void 0!==a&&o.push(a)}),o}}); | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()}(0,function(){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(e)}function e(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("lodash.get");function o(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id";if(t&&"object"!==r(t))throw new Error("Cant convert hash-to-array because hash was not passed in: "+t);var n=Object.assign({},t),a=[];return Object.keys(n).forEach(function(r){var t=n[r],i=!!Object.keys(t).reduce(function(r,e){return!0===t[e]&&r},!0),s=Object.keys(t).every(function(r){return!0===n[r]});i?s?a.push(r):a.push(Object.assign(e({},o,r),{value:n[r]})):a.push(i?r:Object.assign({},t,e({},o,r)))}),a}exports.removeIdPropertyFromHash=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id",t={};return Object.keys(r).map(function(o){var n=r[o];t[o]={},Object.keys(n).map(function(r){r!==e&&(t[o][r]=n[r])})}),t},exports.keyValueDictionaryToArray=function(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=t.key||"key",n=t.value||"value";return Object.keys(r).reduce(function(t,a){var i;return t.concat((e(i={},o,a),e(i,n,r[a]),i))},[])},exports.hashToArray=o,exports.flatten=function r(e){return e.reduce(function(e,t){return e.concat(Array.isArray(t)?r(t):t)},[])},exports.arrayToHash=function(t,o){if(0===t.length)return{};var n="object"!==r(t[0]);if(n&&o){var a=new Error("You can not have an array of primitive values AND set a keyProperty!");throw a.name="NotAllowed",a}if(!o&&!n){if(!t[0].hasOwnProperty("id")){var i=new Error('Tried to default to a keyProperty of "id" but that property does not appear to be in the array passed in');throw i.name="NotAllowed",i}o="id"}if(!Array.isArray(t)){var s=new Error("arrayToHash: input was not an array!");throw s.name="NotAllowed",s}return t.reduce(function(r,t){var a=n?t:t[o];return n?Object.assign({},r,e({},a,!0)):Object.assign({},r,e({},a,t))},{})},exports.snapshotToArray=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id";return o(r.val()||{},e)},exports.snapshotToHash=function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id",n=t.val()||{};return Object.keys(n).forEach(function(t){var a;return"object"===r(n[t])?n[t][o]=t:n[t]=(e(a={},o,t),e(a,"value",n[t]),a)}),n},exports.snapshotToOrderedArray=function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id",n=[];return t.forEach(function(t){var a=t.val(),i=t.key;if("object"!==r(a))throw new Error("Can't create a list from scalar values: \"".concat(a,'" | "').concat(i,'"'));return n.push(Object.assign(e({},o,i),a)),!0}),n},exports.snapshotToOrderedHash=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"id",t=this.snapshotToOrderedArray(r,e);return this.arrayToHash(t)},exports.getPropertyAcrossDictionaryItems=function(r,e){var o=[];return Object.keys(r).map(function(n){var a=t(r[n],e,void 0);void 0!==a&&o.push(a)}),o}}); | ||
//# sourceMappingURL=typed-conversions.min.js.map |
@@ -8,3 +8,3 @@ import { IDictionary } from "common-types"; | ||
export declare function removeIdPropertyFromHash<T = IDictionary>(hash: IDictionary<T>, idProp?: string): any; | ||
export declare function keyValueDictionaryToArray<T = any>(dict: IDictionary<T>): any[]; | ||
export declare function keyValueDictionaryToArray<T = any>(dict: IDictionary<T>, options?: IDictionary): any[]; | ||
export declare function hashToArray<T = any>(hashObj: IDictionary<T> | IDictionary<string> | IDictionary<number>, __key__?: keyof (T & { | ||
@@ -11,0 +11,0 @@ id: string; |
@@ -18,5 +18,7 @@ "use strict"; | ||
exports.removeIdPropertyFromHash = removeIdPropertyFromHash; | ||
function keyValueDictionaryToArray(dict) { | ||
function keyValueDictionaryToArray(dict, options = {}) { | ||
const __key__ = options.key || "key"; | ||
const __value__ = options.value || "value"; | ||
return Object.keys(dict).reduce((result, key) => { | ||
return result.concat({ key, value: dict[key] }); | ||
return result.concat({ [__key__]: key, [__value__]: dict[key] }); | ||
}, []); | ||
@@ -23,0 +25,0 @@ } |
{ | ||
"name": "typed-conversions", | ||
"version": "0.8.6", | ||
"version": "0.8.7", | ||
"description": "typed-conversions", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
31905
321