UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

47 lines (46 loc) 2.47 kB
/*! * shared v9.2.2 * (c) 2022 kazuya kawaguchi * Released under the MIT License. */ const inBrowser = typeof window !== "undefined"; const hasSymbol = typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol"; const makeSymbol = (name) => hasSymbol ? Symbol(name) : name; const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source }); const friendlyJSONstringify = (json) => JSON.stringify(json).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/\u0027/g, "\\u0027"); const isNumber = (val) => typeof val === "number" && isFinite(val); const isDate = (val) => toTypeString(val) === "[object Date]"; const isRegExp = (val) => toTypeString(val) === "[object RegExp]"; const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0; function warn(msg, err) { if (typeof console !== "undefined") { console.warn(`[intlify] ` + msg); if (err) { console.warn(err.stack); } } } const assign = Object.assign; let _globalThis; const getGlobalThis = () => { return _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {}); }; function escapeHtml(rawText) { return rawText.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;"); } const hasOwnProperty = Object.prototype.hasOwnProperty; function hasOwn(obj, key) { return hasOwnProperty.call(obj, key); } const isArray = Array.isArray; const isFunction = (val) => typeof val === "function"; const isString = (val) => typeof val === "string"; const isBoolean = (val) => typeof val === "boolean"; const isObject = (val) => val !== null && typeof val === "object"; const objectToString = Object.prototype.toString; const toTypeString = (value) => objectToString.call(value); const isPlainObject = (val) => toTypeString(val) === "[object Object]"; const toDisplayString = (val) => { return val == null ? "" : isArray(val) || isPlainObject(val) && val.toString === objectToString ? JSON.stringify(val, null, 2) : String(val); }; export { assign, escapeHtml, friendlyJSONstringify, generateFormatCacheKey, getGlobalThis, hasOwn, inBrowser, isArray, isBoolean, isDate, isEmptyObject, isFunction, isNumber, isObject, isPlainObject, isRegExp, isString, makeSymbol, objectToString, toDisplayString, toTypeString, warn };