UNPKG

remap-js

Version:

Give your objects a different shape

20 lines 911 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var chai_1 = require("chai"); var remap_array_1 = require("./remap-array"); describe('remapArray()', function () { it('remaps arrays given object path', function () { var object = { a: [{ b: 1 }, { b: 2 }] }; var expected = [{ c: 1 }, { c: 2 }]; var actual = remap_array_1.remapArray('a', { c: 'b' })(object); chai_1.expect(actual).to.eql(expected); }); it('allows functions that pass object and index', function () { var object = { a: [{ b: 1 }, { b: 2 }] }; var expected = [{ c: '1-0' }, { c: '2-1' }]; var arrayMapping = { c: function (item, index) { return item.b + "-" + index; } }; var actual = remap_array_1.remapArray('a', arrayMapping)(object); chai_1.expect(actual).to.eql(expected); }); }); //# sourceMappingURL=remap-array.spec.js.map