@platform/util.value
Advanced tools
Comparing version 0.1.7 to 0.2.0
@@ -20,1 +20,5 @@ export declare function walk(obj: any | any[], fn: (obj: any | any[]) => void): void; | ||
}; | ||
export declare function toArray<T = any, K = keyof T>(obj: object): Array<{ | ||
key: K; | ||
value: T[keyof T]; | ||
}>; |
@@ -129,2 +129,6 @@ "use strict"; | ||
exports.prune = prune; | ||
function toArray(obj) { | ||
return Object.keys(obj).map(function (key) { return ({ key: key, value: obj[key] }); }); | ||
} | ||
exports.toArray = toArray; | ||
function prepareKeyPath(keyPath) { | ||
@@ -131,0 +135,0 @@ keyPath = keyPath.trim(); |
@@ -170,1 +170,23 @@ "use strict"; | ||
}); | ||
describe('object.toArray', function () { | ||
var foos = { one: { count: 1 }, two: { count: 2 } }; | ||
it('empty', function () { | ||
chai_1.expect(object.toArray({})).to.eql([]); | ||
}); | ||
it('converts to array (untyped)', function () { | ||
var res = object.toArray(foos); | ||
chai_1.expect(res.length).to.eql(2); | ||
}); | ||
it('converts to array (typed object)', function () { | ||
var res = object.toArray(foos); | ||
chai_1.expect(res.length).to.eql(2); | ||
chai_1.expect(res[0].key).to.eql('one'); | ||
chai_1.expect(res[1].key).to.eql('two'); | ||
chai_1.expect(res[0].value).to.eql({ count: 1 }); | ||
chai_1.expect(res[1].value).to.eql({ count: 2 }); | ||
}); | ||
it('converts to array (typed key)', function () { | ||
var res = object.toArray(foos); | ||
chai_1.expect(res.length).to.eql(2); | ||
}); | ||
}); |
{ | ||
"name": "@platform/util.value", | ||
"version": "0.1.7", | ||
"version": "0.2.0", | ||
"description": "Helpers for working with, transforming, and formatting values.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
143958
3760