How to use the @requestnetwork/utils.isString function in @requestnetwork/utils

To help you get started, we’ve selected a few @requestnetwork/utils 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 RequestNetwork / requestNetwork / packages / request-logic / src / actions / create.ts View on Github external
function createRequest(
  action: RequestLogicTypes.IAction,
  timestamp: number,
): RequestLogicTypes.IRequest {
  if (!action.data.parameters.payee && !action.data.parameters.payer) {
    throw new Error('action.parameters.payee or action.parameters.payer must be given');
  }

  if (
    !Utils.isString(action.data.parameters.expectedAmount) ||
    !Utils.amount.isValid(action.data.parameters.expectedAmount)
  ) {
    throw new Error(
      'action.parameters.expectedAmount must be a string representing a positive integer',
    );
  }

  const signer: IdentityTypes.IIdentity = Action.getSignerIdentityFromAction(action);

  // Copy to not modify the action itself
  const request: RequestLogicTypes.IRequest = Utils.deepCopy(action.data.parameters);
  request.extensions = {};
  request.requestId = Action.getRequestId(action);
  request.version = Action.getVersionFromAction(action);
  request.events = [generateEvent(action, timestamp, signer)];
github RequestNetwork / requestNetwork / packages / request-logic / src / amount.ts View on Github external
function isValid(amount: Types.RequestLogicAmount): boolean {
  return (
    (bigNumber.isBN(amount) && !amount.isNeg()) ||
    (Utils.isString(amount) && regexInteger.test(amount)) ||
    (typeof amount === 'number' && (Number.isSafeInteger(Number(amount)) && Number(amount) >= 0))
  );
}