UNPKG

react-antd-admin-panel

Version:

Easy prototyping admin panel using React and Antd

63 lines 2.14 kB
export default class Helpers { static getIndicesOf(searchStr, str, caseSensitive) { let searchStrLen = searchStr.length; if (searchStrLen == 0) return []; let startIndex = 0; let index; let indices = []; if (!caseSensitive) { str = str.toLowerCase(); searchStr = searchStr.toLowerCase(); } while ((index = str.indexOf(searchStr, startIndex)) > -1) { indices.push(index); startIndex = index + searchStrLen; } return indices; } static hash(value, length = 8) { value = Helpers.safeStringify(value); let hash = 5381; let index = value.length; while (index) hash = (hash * 33) ^ value.charCodeAt(--index); hash = hash >>> 0; return hash.toString(length); } static safeStringify(obj, indent = 2) { let cache = []; const retVal = JSON.stringify(obj, (value) => typeof value === "object" && value !== null ? cache.includes(value) ? undefined // Duplicate reference found, discard key : cache.push(value) && value // Store value in our collection : value, indent); cache = null; return retVal; } ; static stamp() { return `S${new Date().getSeconds().toString()}-M${new Date().getMilliseconds().toString()}`; } static store(data, has, fallback) { return Helpers.inside(data, `c.request.store.${has}`, fallback); } static inside(data, has, fallback = undefined) { if (typeof has === 'string') has = has.split('.'); let temp = data; let fail = false; has.forEach((r) => { if (!temp) fail = true; if (!fail && r in temp) { temp = temp[r]; } else { temp = undefined; } }); return temp !== null && temp !== void 0 ? temp : fallback; } } //# sourceMappingURL=Helpers.js.map