💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## [shared\util.js] >[info] import ~~~ ;转换为字符串输出 export function renderString (val) { return val == null ? '' : typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val) } ;字符串转换为Map结构,并检查key是否在Map中 export function makeMap (str, expectsLowerCase) { const map = Object.create(null) const list = str.split(',') for (let i = 0; i < list.length; i++) { map[list[i]] = true } return expectsLowerCase ? val => map[val.toLowerCase()] : val => map[val] } ;自定义内建标签 export const isBuiltInTag = makeMap('slot,component,render,transition', true) ;删除数组的项 export function remove (arr, item) { if (arr.length) { const index = arr.indexOf(item) if (index > -1) { return arr.splice(index, 1) } } } ;检测是否为对象的属性 const hasOwnProperty = Object.prototype.hasOwnProperty export function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } ;检测是否为原子类型(数字和字符串) export function isPrimitive (value) { return typeof value === 'string' || typeof value === 'number' } ;函数的缓存版本 export function cached (fn) { const cache = Object.create(null) return function cachedFn (str) { const hit = cache[str] return hit || (cache[str] = fn(str)) } } const camelizeRE = /-(\w)/g ;字符串驼峰化 export const camelize = cached(str => { return str.replace(camelizeRE, toUpper) }) function toUpper (_, c) { return c ? c.toUpperCase() : '' } const hyphenateRE = /([a-z\d])([A-Z])/g ;字符串解驼峰 export const hyphenate = cached(str => { return str .replace(hyphenateRE, '$1-$2') .toLowerCase() }) ;函数绑定环境运行 export function bind (fn, ctx) { return function (a) { const l = arguments.length return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx) } } ;数组类对象转换为数组 export function toArray (list, start) { start = start || 0 let i = list.length - start const ret = new Array(i) while (i--) { ret[i] = list[i + start] } return ret } ;属性合并 export function extend (to, _from) { for (const key in _from) { to[key] = _from[key] } return to } ;检测是否为对象 export function isObject (obj) { return obj !== null && typeof obj === 'object' } ;检测是否为简单对象 const toString = Object.prototype.toString const OBJECT_STRING = '[object Object]' export function isPlainObject (obj) { return toString.call(obj) === OBJECT_STRING } ;检测是否为数组 export const isArray = Array.isArray ~~~ >[info] module ~~~ ~~~ >[info] export ~~~ ;(导出)字符串输出 export function renderString (val) {} ;(导出)字符串到Map结构转换 export function makeMap (str, expectsLowerCase) {} ;(导出)自定义内置标签 export const isBuiltInTag ;(导出)删除数组项 export function remove (arr, item) {} ;(导出)检测对象属性 export function hasOwn (obj, key) {} ;(导出)检测值是否是数字和字符串原子类型 export function isPrimitive (value) {} ;(导出)函数的缓存版本 export function cached (fn) {} ;(导出)字符串驼峰化 export const camelize{} ;(导出)字符串解驼峰化 export const hyphenate{} ;(导出)函数绑定环境运行 export function bind (fn, ctx) {} ;(导出)对象转换为数组 export function toArray (list, start) {} ;(导出)合并对象属性 export function extend (to, _from) {} ;(导出)检测是否为对象 export function isObject (obj) {} ;(导出)检测是否为简单对象 export function isPlainObject (obj) {} ;(导出)检测是否为数组 export const isArray ~~~