本文整理汇总了TypeScript中kind-of.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: make
/**
* A utility for safely converting an object a `DataEntity`.
* This will detect if passed an already converted input and return it.
*
* NOTE: `DataEntity.make` is different from using `new DataEntity`
* because it attaching it doesn't shallow cloning the object
* onto the `DataEntity` instance, this is significatly faster and so it
* is recommended to use this in production.
*/
static make(input: DataInput, metadata?: object): DataEntity {
if (input == null) return new DataEntity({});
if (DataEntity.isDataEntity(input)) return input;
if (!isPlainObject(input)) {
throw new Error(`Invalid data source, must be an object, got "${kindOf(input)}"`);
}
Object.defineProperties(input, {
getMetadata: {
value(key?: string) {
return getMetadata(this, key);
},
enumerable: false,
writable: false
},
setMetadata: {
value(key: string, value: any) {
return setMetadata(this, key, value);
},
enumerable: false,
writable: false
},
toBuffer: {
value(opConfig: EncodingConfig = {}) {
return toBuffer(this, opConfig);
},
enumerable: false,
writable: false
}
});
const entity = input as DataEntity;
_metadata.set(entity, Object.assign({ createdAt: Date.now() }, metadata));
return entity as DataEntity;
}
示例2: TypeError
export function parseJSON<T = object>(buf: Buffer|string): T {
if (!Buffer.isBuffer(buf) && !isString(buf)) {
throw new TypeError(`Failure to serialize non-buffer, got "${kindOf(buf)}"`);
}
try {
// @ts-ignore because it does work with buffers
return JSON.parse(buf);
} catch (err) {
throw new Error(`Failure to parse buffer, ${toString(err)}`);
}
}
示例3: Error
constructor(data: object, metadata?: object) {
_metadata.set(this, fastAssign({ createdAt: Date.now() }, metadata));
if (data == null) return;
if (DataEntity.isDataEntity(data)) return data;
if (!isPlainObject(data)) {
throw new Error(`Invalid data source, must be an object, got "${kindOf(data)}"`);
}
fastAssign(this, data);
}
示例4: sampleFunction
function sampleFunction() {
kindOf(arguments);
// => 'arguments'
}