UNPKG

@cloudpss/template

Version:

Lightweight string and object templating utilities with interpolation and formula support.

37 lines 1.28 kB
/** 是否为 ArrayBuffer */ export let isArrayBuffer; /** 是否为 Error */ export let isError; if (typeof Error.isError == 'function') { isError = Error.isError; } if (typeof process == 'object' && typeof process.getBuiltinModule == 'function') { const typeUtils = process.getBuiltinModule('node:util/types'); isArrayBuffer = typeUtils.isAnyArrayBuffer; isError = typeUtils.isNativeError; } isError ??= (value) => { return value instanceof Error; }; isArrayBuffer ??= (value) => { const tag = toString(value); return tag === '[object ArrayBuffer]' || tag === '[object SharedArrayBuffer]'; }; /** * Object.prototype.toString.call 的快捷方式 */ // eslint-disable-next-line @typescript-eslint/unbound-method export const toString = Function.call.bind(Object.prototype.toString); export const { hasOwn } = Object; export const { isArray } = Array; export const isArrayBufferView = ArrayBuffer.isView.bind(ArrayBuffer); export const { stringify } = JSON; /** * 获取 ArrayBuffer 的拷贝 */ export function copyArrayBuffer(buffer, start, length) { const copy = new ArrayBuffer(length ?? buffer.byteLength - start); new Uint8Array(copy).set(new Uint8Array(buffer, start, length)); return copy; } //# sourceMappingURL=utils.js.map