本文整理匯總了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'
}