|
|
@ -1,7 +1,7 @@ |
|
|
|
let fs = require('fs'); |
|
|
|
let { logger } = require('./logging'); |
|
|
|
|
|
|
|
function getShortestPrefix(radixTree, key, sliceSize) { |
|
|
|
function getShortestPrefix(radixTree: any, key: string, sliceSize: number) { |
|
|
|
let shortKey = key.substring(0, sliceSize); |
|
|
|
let keyCount = radixTree.countPrefix(shortKey); |
|
|
|
if (keyCount < 1) { |
|
|
@ -16,8 +16,8 @@ function getShortestPrefix(radixTree, key, sliceSize) { |
|
|
|
return getShortestPrefix(radixTree, key, sliceSize + 1); |
|
|
|
} |
|
|
|
|
|
|
|
function toISODateString(d) { |
|
|
|
function pad(n) { return n < 10 ? '0' + n : n } |
|
|
|
function toISODateString(d: Date) { |
|
|
|
function pad(n: number) { return n < 10 ? '0' + n : n } |
|
|
|
return d.getUTCFullYear() + '-' |
|
|
|
+ pad(d.getUTCMonth() + 1) + '-' |
|
|
|
+ pad(d.getUTCDate()) + 'T' |
|
|
@ -39,17 +39,17 @@ function getBuildInfo() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function sleep(ms) { |
|
|
|
function sleep(ms: number) { |
|
|
|
return new Promise(resolve => { |
|
|
|
setTimeout(resolve, ms) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function isString(s) { |
|
|
|
function isString(s: any) { |
|
|
|
return typeof (s) === 'string' || s instanceof String; |
|
|
|
} |
|
|
|
|
|
|
|
function isFunction(f) { |
|
|
|
function isFunction(f: any) { |
|
|
|
return f && {}.toString.call(f) === '[object Function]'; |
|
|
|
} |
|
|
|
|
|
|
@ -61,26 +61,25 @@ function isFunction(f) { |
|
|
|
* |
|
|
|
* @param {*} initialObj The starting object to derive the from |
|
|
|
* @param {*} sentinelPrototype The prototype that represents the end of the line |
|
|
|
* @param {*} filterFunc A fioltering function for the return names |
|
|
|
* @param {*} filterFunc A filtering function for the return names |
|
|
|
*/ |
|
|
|
function getObjectKeysToPrototype(initialObj, sentinelPrototype, filterFunc = (e) => true) { |
|
|
|
function getObjectKeysToPrototype(initialObj: any, sentinelPrototype: any, filterFunc: any = (e: any) => true) { |
|
|
|
let prototypeChain = [] |
|
|
|
var targetPrototype = initialObj; |
|
|
|
while (Object.getPrototypeOf(targetPrototype) && targetPrototype !== sentinelPrototype) { |
|
|
|
targetPrototype = Object.getPrototypeOf(targetPrototype); |
|
|
|
prototypeChain.push(targetPrototype); |
|
|
|
} |
|
|
|
// console.log("Prototype chain: %s", prototypeChain);
|
|
|
|
let completePropertyNames = prototypeChain.map((obj) => { |
|
|
|
return Object.getOwnPropertyNames(obj); |
|
|
|
}) |
|
|
|
return [Object.getOwnPropertyNames(initialObj)].concat.apply([], completePropertyNames).filter(filterFunc); |
|
|
|
} |
|
|
|
|
|
|
|
exports.getShortestPrefix = getShortestPrefix; |
|
|
|
exports.toISODateString = toISODateString; |
|
|
|
exports.getBuildInfo = getBuildInfo; |
|
|
|
exports.sleep = sleep; |
|
|
|
exports.isString = isString; |
|
|
|
exports.isFunction = isFunction; |
|
|
|
exports.getObjectKeysToPrototype = getObjectKeysToPrototype; |
|
|
|
export { getShortestPrefix }; |
|
|
|
export { toISODateString }; |
|
|
|
export { getBuildInfo }; |
|
|
|
export { sleep }; |
|
|
|
export { isString }; |
|
|
|
export { isFunction }; |
|
|
|
export { getObjectKeysToPrototype }; |