Support

This is a Collection of Helpers for the Platform SDK. The implementation adheres to the contracts laid out in the specification.

Repository

Installation

1yarn add @ardenthq/sdk-helpers

Usage

Arr

Importing the Arr class

1import { Arr } from "@ardenthq/sdk-helpers";

Get a random element from the given array

1Arr.randomElement(items: any[]);

Bignumber

Importing the BigNumber class

1import { BigNumber } from "@ardenthq/sdk-helpers";

Create a new BigNumber instance from the given value

1BigNumber.make(value: NumberLike, decimals?: number): BigNumber;

Set the amount of decimals to the given limit

1bigNumber.decimalPlaces(decimals?: number): BigNumber;

Add the given value to the existing value

1bigNumber.plus(value: NumberLike): BigNumber;

Subtract the given value from the existing value

1bigNumber.minus(value: NumberLike): BigNumber;

Divide the existing value by the given value

1bigNumber.divide(value: NumberLike): BigNumber;

Multiply the existing value by the given value

1bigNumber.times(value: NumberLike): BigNumber;

Determine if the value is NaN

1bigNumber.isNaN(): boolean;

Determine if the value is positive

1bigNumber.isPositive(): boolean;

Determine if the value is finite

1bigNumber.isFinite(): boolean;

Get the difference between the given and actual value

1bigNumber.comparedTo(value: NumberLike): number;

Determine if the actual value is equal to the expected value

1bigNumber.isEqualTo(value: NumberLike): boolean;

Determine if the actual value is greater than the expected value

1bigNumber.isGreaterThan(value: NumberLike): boolean;

Determine if the actual value is greater than or equal to the expected value

1bigNumber.isGreaterThanOrEqualTo(value: NumberLike): boolean;

Determine if the actual value is less than the expected value

1bigNumber.isLessThan(value: NumberLike): boolean;

Determine if the actual value is less than or equal to the expected value

1bigNumber.isLessThanOrEqualTo(value: NumberLike): boolean;

Return the value as satoshis

1bigNumber.toSatoshi(): BigNumber;

Return the value as human-readable number

1bigNumber.toHuman(decimals = 8): string;

Return the value as a string with a limited amount of decimals

1bigNumber.toFixed(decimals?: number): string;

Return the value as an integer

1bigNumber.toNumber(): number;

Return the value as a string

1bigNumber.toString(): string;

Return the value as a string, including the minus symbol if applicable

1bigNumber.valueOf(): string;

Censor

Importing the Censor class

1import { Censor } from "@ardenthq/sdk-helpers";
2 
3const censor = new Censor();

Determine if the value contains bad terms

1censor.isBad(value: string): boolean;

Remove all bad terms from the value

1censor.process(value: string): string;

Markdown

Importing the Markdown class

1import { Markdown } from "@ardenthq/sdk-helpers";

Parse the given content into HTML

1Markdown.parse(content: string): { meta: MarkdownMeta; content: String };

QRCode

Importing the QRCode class

1import { QRCode } from "@ardenthq/sdk-helpers";

Create a new QRCode from a string

1QRCode.fromString(value: string): QRCode;

Create a new QRCode from an object of keys and values

1QRCode.fromObject(value: object): QRCode;

Get the Base64 Data URL representation of the QRCode

1await qrcode.toDataURL(options: QRCodeToDataURLOptions = {}): Promise<string>;

Get the string representation of the QRCode

1await qrcode.toString(type: StringType = "utf8"): Promise<string>;

Validator

Importing the Validator class

1import { Validator } from "@ardenthq/sdk-helpers";
2 
3const validator = new Validator();

Validate the given data against the schema

1validator.validate(data: object, schema: { validateSync: Function }): void;

Check if the validation passed

1validator.passes(): boolean;

Check if the validation failed

1validator.fails(): boolean;

Get a list of all error messages

1validator.errors(): string[] | undefined;

Get the error object from yup

1validator.error(): ValidationError | undefined;

Security

If you discover a security vulnerability within this package, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.

Last updated 2 years ago
Edit Page
Share: