UNPKG

kitten-cloud-function

Version:

用于编程猫源码云功能(云变量、云列表等)的客户端工具

63 lines (62 loc) 1.94 kB
export const None = null; export function equal(a, b) { if (a === b) { return true; } if (a && b && typeof a == "object" && typeof b == "object") { if (a.constructor != b.constructor) { return false; } if (Array.isArray(a)) { if (a.length != b.length) { return false; } for (let i = 0; i < a.length; i++) { if (!equal(a[i], b[i])) { return false; } } return true; } let keys = Object.keys(a); if (keys.length != Object.keys(b).length) { return false; } for (const key of keys) { if (!(key in b) || !equal(a[key], b[key])) { return false; } } return true; } return false; } export function merge(target, source) { for (const key in source) { if (typeof source[key] == "object" && source[key] != None) { if (!(key in target)) { target[key] = {}; } if (typeof target[key] == "object" && target[key] != None) { merge(target[key], source[key]); } } else if (!(key in target)) { target[key] = source[key]; } } return target; } export function enumerable(value) { return function (__target, __propertyKey, descriptor) { descriptor.enumerable = value; }; } export const NUMBER_CHAR = "0123456789", LOWER_CASE_LETTER = "abcdefghijklmnopqrstuvwxyz", UPPER_CASE_LETTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", LETTER = LOWER_CASE_LETTER.concat(UPPER_CASE_LETTER); export function randomString(length = 32, charset = NUMBER_CHAR.concat(LETTER)) { let result = ""; for (let i = 0; i < length; i++) { result += charset[Math.floor(Math.random() * charset.length)]; } return result; }