How to use the @polkadot/util.isString function in @polkadot/util

To help you get started, we’ve selected a few @polkadot/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / api / packages / types / src / ContractAbi.ts View on Github external
private _convertType (type: ContractABITypes): string {
    if (isString(type)) {
      return type;
    } else if (Array.isArray(type)) {
      return `(${type.map((type) => this._convertType(type)).join(',')})`;
    } else if (type['Option']) {
      return `Option<${this._convertType(type['Option'].T)}>`;
    } else if (type['Result']) {
      return `()`; // Result is not supported, but only applicable for returns
    } else if (type['Vec']) {
      return `Vec<${this._convertType(type['Vec'].T)}>`;
    } else if (type['[T;n]']) {
      return `[${this._convertType(type['[T;n]'].T)};${type['[T;n]'].n}]`;
    }

    throw new Error(`Unknown type specified ${JSON.stringify(type)}`);
  }
github polkadot-js / client / packages / client-db / src / block / keys.ts View on Github external
const createMethod = (method: string, key: string, { documentation, type }: SubstrateMetadata): any => {
  const creator = createFunction(
    {
      meta: {
        documentation: new Vec(Text, documentation),
        modifier: createType('StorageEntryModifierV7', 1), // default
        type: new StorageEntryType(type, isString(type) ? 0 : 1),
        toJSON: (): any => key
      } as unknown as StorageEntryMetadata,
      method,
      prefix,
      section
    },
    { key, skipHashing: true }
  );

  return ((...args: any[]): Uint8Array =>
    blake2AsU8a(creator(...args))
  ) as any;
};
github vue-polkadot / vue-ui / packages / vue-keyring / src / Keyring.ts View on Github external
public isAvailable(_address: Uint8Array | string): boolean {
    const accountsValue = this.accounts.subject.getValue();
    const addressesValue = this.addresses.subject.getValue();
    const contractsValue = this.contracts.subject.getValue();
    const address = isString(_address)
      ? _address
      : this.encodeAddress(_address);

    return !accountsValue[address] && !addressesValue[address] && !contractsValue[address];
  }
github polkadot-js / ui / packages / ui-keyring / src / Keyring.ts View on Github external
public getAddress (_address: string | Uint8Array, type: KeyringItemType | null = null): KeyringAddress | undefined {
    const address = isString(_address)
      ? _address
      : this.encodeAddress(_address);
    const publicKey = this.decodeAddress(address);
    const stores = type
      ? [this.stores[type]]
      : Object.values(this.stores);

    const info = stores.reduce((lastInfo, store): SingleAddress | undefined =>
      (store().subject.getValue()[address] || lastInfo), undefined);

    return info && {
      address,
      publicKey,
      meta: info.json.meta
    };
  }
github vue-polkadot / vue-ui / packages / vue-keyring / src / Keyring.ts View on Github external
public getAddress(_address: string | Uint8Array, type: KeyringItemType | null = null): KeyringAddress | undefined {
    const address = isString(_address)
      ? _address
      : this.encodeAddress(_address);
    const publicKey = this.decodeAddress(address);
    const stores = type
      ? [this.stores[type]]
      : Object.values(this.stores);

    const info = stores.reduce((lastInfo, store): SingleAddress | undefined =>
      (store().subject.getValue()[address] || lastInfo), undefined);

    return info && {
      address,
      publicKey,
      meta: info.json.meta,
    };
  }
github polkadot-js / common / packages / util-crypto / src / key / DeriveJunction.ts View on Github external
public soft (value: number | BN | string | Uint8Array): DeriveJunction {
    if (isNumber(value) || isBn(value)) {
      return this.soft(bnToHex(value, BN_OPTIONS));
    } else if (isString(value)) {
      return isHex(value)
        ? this.soft(hexToU8a(value))
        : this.soft(compactAddLength(stringToU8a(value)));
    }

    if (value.length > JUNCTION_ID_LEN) {
      return this.soft(blake2AsU8a(value));
    }

    this._chainCode.fill(0);
    this._chainCode.set(value, 0);

    return this;
  }
github polkadot-js / api / packages / types / src / ContractAbi.ts View on Github external
messages.forEach((method) => {
    const unknownKeys = Object.keys(method).filter((key) => !['args', 'mutates', 'name', 'selector', 'return_type'].includes(key));

    assert(unknownKeys.length === 0, `Unknown keys ${unknownKeys.join(', ')} found in ABI args for messages.${method.name}`);
    assert(isString(method.name), `Expected name for messages.${method.name}`);
    assert(isNumber(method.selector), `Expected selector for messages.${method.name}`);
    assert(isNull(method.return_type) || isString(method.return_type) || isObject(method.return_type), `Expected return_type for messages.${method.name}`);

    validateArgs(`messages.${method.name}`, method.args);
  });
}
github vue-polkadot / vue-ui / packages / vue-keyring / src / Base.ts View on Github external
public isAvailable(_address: Uint8Array | string): boolean {
    const accountsValue = this.accounts.subject.getValue();
    const addressesValue = this.addresses.subject.getValue();
    const contractsValue = this.contracts.subject.getValue();
    const address = isString(_address)
      ? _address
      : this.encodeAddress(_address);

    return !accountsValue[address] && !addressesValue[address] && !contractsValue[address];
  }
github polkadot-js / ui / packages / react-qr / src / util.ts View on Github external
export function createImgSize (size?: string | number): Record {
  if (!size) {
    return {
      height: 'auto',
      width: '100%'
    };
  }

  const height = isString(size)
    ? size
    : `${size}px`;

  return {
    height,
    width: height
  };
}
github polkadot-js / api / packages / types / src / codec / Date.ts View on Github external
public static decodeDate (value: CodecDate | Date | AnyNumber): Date {
    if (value instanceof Date) {
      return value;
    } else if (isU8a(value)) {
      value = u8aToBn(value.subarray(0, BITLENGTH / 8), true);
    } else if (isString(value)) {
      value = new BN(value, 10, 'le');
    }

    return new Date(
      bnToBn(value as BN).toNumber() * 1000
    );
  }