當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。