当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript kind-of.default函数代码示例

本文整理汇总了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;
    }
开发者ID:jeffmontagna,项目名称:teraslice,代码行数:44,代码来源:data-entity.ts

示例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)}`);
    }
}
开发者ID:jeffmontagna,项目名称:teraslice,代码行数:12,代码来源:utils.ts

示例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);
    }
开发者ID:jeffmontagna,项目名称:teraslice,代码行数:13,代码来源:data-entity.ts

示例4: sampleFunction

function sampleFunction() {
    kindOf(arguments);
    // => 'arguments'
}
开发者ID:csrakowski,项目名称:DefinitelyTyped,代码行数:4,代码来源:kind-of-tests.ts


注:本文中的kind-of.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。