當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript object-hash類代碼示例

本文整理匯總了TypeScript中object-hash的典型用法代碼示例。如果您正苦於以下問題:TypeScript object-hash類的具體用法?TypeScript object-hash怎麽用?TypeScript object-hash使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了object-hash類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

 let indexOf = (array: any[], value: any, fromIndex?: number): number => {
     let startIndex: number = fromIndex ? fromIndex : 0;
     for (var i = startIndex; i < array.length; i++) {
         if (hash(array[i]) === hash(value)) {
             return i;
         }
     }
     return -1;
 };
開發者ID:hydra-newmedia,項目名稱:chrobject,代碼行數:9,代碼來源:DeepDiff.ts

示例2: unsetIgnoredSubProperties

        _.keys(one).forEach((key) => {
            let concatPath: string = path ? path + '.' + key : key;
            if (!_.includes(this.options.ignoreProperties, concatPath) && !_.includes(this.options.ignoreSubProperties, concatPath)) {

                unsetIgnoredSubProperties(one[key]);
                unsetIgnoredSubProperties(two[key]);

                let getDeletedProperties = (obj: any, propPath: string = null) => {
                    if (_.isPlainObject(obj)) {
                        for (var objKey of _.keys(obj)) {
                            unsetIgnoredSubProperties(obj[objKey]);
                            getDeletedProperties(obj[objKey], propPath ? propPath + '.' + objKey : objKey);
                        }
                    } else if (_.isBoolean(obj) || _.isDate(obj) || _.isNumber(obj)
                        || _.isNull(obj) || _.isRegExp(obj) || _.isString(obj) || _.isArray(obj)) {
                        result.push(new DeepDiff('deleted', propPath, obj, null));
                    }
                };

                if (_.isPlainObject(one[key])) {
                    if (!_.has(two, key)) {
                        getDeletedProperties(one[key], concatPath);
                    } else {
                        result = _.concat(result, this.deepDiff(one[key], two[key], path ? path + '.' + key : key));
                    }
                } else if (_.isBoolean(one[key]) || _.isDate(one[key]) || _.isNumber(one[key])
                    || _.isNull(one[key]) || _.isRegExp(one[key]) || _.isString(one[key])) {
                    if (!_.has(two, key)) {
                        result.push(new DeepDiff('deleted', concatPath, one[key], null));
                    } else if (_.isDate(one[key]) || _.isDate(two[key])) {
                        if (new Date(one[key]).valueOf() !== new Date(two[key]).valueOf()) {
                            result.push(new DeepDiff('edited', concatPath, new Date(one[key]), new Date(two[key])));
                        }
                    } else if (hash(one[key]) !== hash(two[key])) {
                        result.push(new DeepDiff('edited', concatPath, one[key], two[key]));
                    }
                } else if (_.isArray(one[key]) && _.isArray(two[key]) && !_.isEqual(one[key], two[key])) {
                    for (var i = 0; i < one[key].length; i++) {
                        unsetIgnoredSubProperties(one[key][i]);
                    }
                    for (var i = 0; i < two[key].length; i++) {
                        unsetIgnoredSubProperties(two[key][i]);
                    }
                    if (hash(one[key]) !== hash(two[key])) {
                        result.push(new DeepDiff('array', concatPath, one[key], two[key]));
                    }
                } else if (!_.has(two, key)) {
                    getDeletedProperties(one[key], concatPath);
                }
            }
        });
開發者ID:hydra-newmedia,項目名稱:chrobject,代碼行數:51,代碼來源:EntryAppService.ts

示例3: getStoreId

function getStoreId(
  resolvedUrl: string|null,
  selectorFilters: ISelectorFilter[]|null = null,
  nodeFilters: string[]|null = null,
) {
  return hash({
    resolvedUrl,
    selectorFilters,
    nodeFilters,
  }, { unorderedArrays: true });
}
開發者ID:maoberlehner,項目名稱:node-sass-magic-importer,代碼行數:11,代碼來源:index.ts

示例4: it

 it('should force global scope when it is not set', () => {
   const scope = 'global';
   const token = factory.create(Module as any, [Module], undefined);
   expect(token).to.be.deep.eq(
     hash({
       module: Module.name,
       dynamic: '',
       scope,
     }),
   );
 });
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:11,代碼來源:module-token-factory.spec.ts

示例5: validateAll

 validateAll(): void {
   if (!this.objects) { return; }
   for (let object of this.objects) {
     for (let field of object.metadata) {
       field.valid = this.validFieldValues(field);
     }
     /**
      * Taking advantage of a metadata hash bug
      * Update the hash to get status colors to update
      */
     object.metadataHash = hash(object.metadata);
   }
 }
開發者ID:uhlibraries-digital,項目名稱:brays,代碼行數:13,代碼來源:valication.service.ts

示例6: create

 public create(
   metatype: Type<any>,
   scope: Type<any>[],
   dynamicModuleMetadata?: Partial<DynamicModule> | undefined,
 ): string {
   const reflectedScope = this.reflectScope(metatype);
   const isSingleScoped = reflectedScope === true;
   const opaqueToken = {
     module: this.getModuleName(metatype),
     dynamic: this.getDynamicMetadataToken(dynamicModuleMetadata),
     scope: isSingleScoped ? this.getScopeStack(scope) : reflectedScope,
   };
   return hash(opaqueToken);
 }
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:14,代碼來源:module-token-factory.ts

示例7: setArrayDiffs

    setArrayDiffs(one: any[], two: any[]): void {
        this.arrayDiffs = [];

        let processedItems: { [key: string]: number[] } = {};

        let addToProcessed = (alreadyDoneMap: { [key: string]: number[] }, valHash: string, idx: number) => {
            if (_.has(alreadyDoneMap, valHash)) {
                alreadyDoneMap[valHash].push(idx);
            } else {
                alreadyDoneMap[valHash] = [idx];
            }
        };

        // indexOf function which checks for object hash equality instead of using SameValueZero
        let indexOf = (array: any[], value: any, fromIndex?: number): number => {
            let startIndex: number = fromIndex ? fromIndex : 0;
            for (var i = startIndex; i < array.length; i++) {
                if (hash(array[i]) === hash(value)) {
                    return i;
                }
            }
            return -1;
        };

        // loop through first array to find deletions and index changes
        for (var idxInOne = 0; idxInOne < one.length; idxInOne++) {
            let val: any = one[idxInOne];
            // check whether item is in second array
            if (indexOf(two, val) >= 0) {
                // check whether already processed a similar item
                let valHash: string = hash(val);
                // get idx in second array where the last processed item was moved to
                let idxLastMovedTo: number = _.has(processedItems, valHash) ? _.last<number>(processedItems[valHash]) + 1 : undefined;
                // search from there on
                let idxMovedTo: number = indexOf(two, val, idxLastMovedTo);
                if (idxInOne === idxMovedTo) {
                    // if element stayed, just add it to processed elements
                    addToProcessed(processedItems, valHash, idxInOne);
                } else if (idxMovedTo >= 0) {
                    // if moved, add it to processed elements and output change
                    addToProcessed(processedItems, valHash, idxMovedTo);
                    this.arrayDiffs.push(new ArrayDiff('moved', idxInOne, val, idxMovedTo));
                } else {
                    // if no such element found, output deletion
                    this.arrayDiffs.push(new ArrayDiff('removed', idxInOne, val));
                }
            } else {
                // if not found at all, output deletion
                this.arrayDiffs.push(new ArrayDiff('removed', idxInOne, val));
            }
        }

        // loop through second array to find additions in comparison to first array
        for (var idxInTwo = 0; idxInTwo < two.length; idxInTwo++) {
            let val: any = two[idxInTwo];
            let valHash: string = hash(val);
            // check if element is not in processed elements map or if it is, then not at the same position
            if (!_.has(processedItems, valHash) || _.indexOf(processedItems[valHash], idxInTwo) < 0) {
                // output additions
                this.arrayDiffs.push(new ArrayDiff('added', idxInTwo, val));
            }
        }
    }
開發者ID:hydra-newmedia,項目名稱:chrobject,代碼行數:63,代碼來源:DeepDiff.ts


注:本文中的object-hash類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。