ts-essentials#Dictionary TypeScript Examples

The following examples show how to use ts-essentials#Dictionary. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArrayWith.ts    From earl with MIT License 6 votes vote down vote up
/** @internal */
export function contains(expectedItems: ReadonlyArray<any>, actualItems: ReadonlyArray<any>): boolean {
  const matchedIndexes: Dictionary<boolean, number> = {}

  return expectedItems.every((expectedItem) => {
    const foundIndex = actualItems.findIndex(
      (actualItem, index) => isEqual(actualItem, expectedItem) && !matchedIndexes[index],
    )

    if (foundIndex !== -1) {
      matchedIndexes[foundIndex] = true

      return true
    } else {
      return false
    }
  })
}
Example #2
Source File: index.ts    From fuels-ts with Apache License 2.0 5 votes vote down vote up
private readonly contractCache: Dictionary<
    | {
        abi: RawAbiDefinition[];
        contract: Contract;
      }
    | undefined
  > = {};
Example #3
Source File: abiParser.ts    From fuels-ts with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the JSON abi
 */
export function parse(
  abi: RawAbiDefinition[],
  rawName: string,
  documentation?: DocumentationResult
): Contract {
  const functions: FunctionDeclaration[] = [];

  const structs: TupleType[] = [];
  /**
   * Registers Structs used in the abi
   */
  function registerStruct(newStruct: TupleType): void {
    if (structs.findIndex((s) => s.structName === newStruct.structName) === -1) {
      structs.push(newStruct);
    }
  }

  abi.forEach((abiPiece) => {
    if (abiPiece.type === 'function') {
      functions.push(parseFunctionDeclaration(abiPiece, registerStruct, documentation));
    }
  });

  const functionGroup = functions.reduce((memo, value) => {
    if (Array.isArray(memo[value.name])) {
      memo[value.name].push(value);
    } else {
      memo[value.name] = [value];
    }
    return memo;
  }, {} as Dictionary<FunctionDeclaration[]>);

  const structGroup = structs.reduce((memo, value) => {
    if (memo[value.structName]) {
      memo[value.structName].push(value);
    } else {
      memo[value.structName] = [value];
    }
    return memo;
  }, {} as Dictionary<TupleType[]>);

  return {
    name: normalizeName(rawName),
    rawName,
    functions: functionGroup,
    structs: structGroup,
  };
}