UNPKG

@aappddeevv/dynamics-client-ui

Version:

## What is it? A library to help you create great dynamics applications.

39 lines 1.26 kB
"use strict"; /** Misc data management utilities. */ Object.defineProperty(exports, "__esModule", { value: true }); /** Decent string hash. */ function hash(str) { var hash = 5381; for (let i = 0; i < str.length; i++) { const char = str.charCodeAt(i); hash = ((hash << 5) + hash) + char; /* hash * 33 + c */ } return hash; } exports.hash = hash; /** Clean the id of brackets and lowercase everything. */ function cleanId(id) { if (typeof id === "undefined" || id === null) throw Error(`Unable to clean nil id ${id}`); return id.toString().replace(/[{}]/g, "").toLowerCase(); } exports.cleanId = cleanId; /** Wrap an id with {} and cap it, if needed. */ function wrapId(id) { return `${cleanId(id).toUpperCase()}`; } exports.wrapId = wrapId; /** Simple normalization of data using a function to obtain the key. */ function normalize(id, data, tx) { return data.reduce((accum, t) => { accum[id(t)] = tx(t); return accum; }, {}); } exports.normalize = normalize; /** Normalize with a key that accessed via a simple key lookup. */ function normalizeWith(key, data) { return normalize(t => t[key], data, (t) => t); } exports.normalizeWith = normalizeWith; //# sourceMappingURL=Utils.js.map