UNPKG

@librecoder/tools

Version:

![build](https://img.shields.io/badge/build-passing-success.svg)

45 lines (39 loc) 890 B
import {getType} from "./type"; export function clone(target) { let rs const targetType = getType(target) if (targetType === 'Object') { rs = {} } else if (targetType === 'Array') { rs = [] } else { return target; } for (const i in target) { rs[i] = clone(target[i]) } return rs } export function hasProperty(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key) } // 删除数组中的某一项 export function arrayRemove(arr, val) { if (arr.length) { const index = arr.indexOf(val) if (index > -1) { return arr.splice(index, 1) } } } // 删除对象中的某一项 export function objectRemove(obj, key) { if (hasProperty(obj, key)) { delete obj[key] } } export function uuid(){ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16) }) }