Skip to main content
Version: Next

Namespace: shortString

Functions

isASCII

isASCII(str): boolean

Test if string contains only ASCII characters (string can be ascii text)

Parameters

NameTypeDescription
strstringThe string to test

Returns

boolean

Returns true if the string contains only ASCII characters, otherwise false

Example

const result = shortString.isASCII("Hello, world!");
// result = true
const result = shortString.isASCII("Hello, 世界!");
// result = false

Defined in

src/utils/shortString.ts:18


isShortString

isShortString(str): boolean

Test if a string is a Cairo short string (string with less or equal 31 characters)

Parameters

NameTypeDescription
strstringthe string to test

Returns

boolean

Returns true if the string has less than or equal to 31 characters, otherwise false.

Example

const result = shortString.isShortString("Hello, world!");
// result = true

Defined in

src/utils/shortString.ts:33


isDecimalString

isDecimalString(str): boolean

Test if string contains only numbers (string can be converted to decimal integer number)

Parameters

NameTypeDescription
strstringthe string to test.

Returns

boolean

Returns true if the string contains only numbers, otherwise false.

Example

const result = shortString.isDecimalString("12345");
// result = true
const result = shortString.isDecimalString("12a45");
// result = false

Defined in

src/utils/shortString.ts:49


isText

isText(val): boolean

Test if value is a pure string text, and not a hex string or number string

Parameters

NameTypeDescription
valanythe value to test

Returns

boolean

returns true if the value is a free-form string text, otherwise false

Example

const result = shortString.isText("Hello, world!");
// result = true
const result = shortString.isText("0x7aec92f706");
// result = false

Defined in

src/utils/shortString.ts:65


splitLongString

splitLongString(longStr): string[]

Split long text (string greater than 31 characters) into short strings (string lesser or equal 31 characters)

Parameters

NameTypeDescription
longStrstringthe long text (string greater than 31 characters) to split

Returns

string[]

an array of short strings (string lesser or equal 31 characters).

Example

const result = shortString.splitLongString("Hello, world! we just testing splitLongString function.");
// result = [ 'Hello, world! we just testing s', 'plitLongString function.' ]

Defined in

src/utils/shortString.ts:103


encodeShortString

encodeShortString(str): string

Convert an ASCII short string to a hexadecimal string.

Parameters

NameTypeDescription
strstringshort string (ASCII string, 31 characters max)

Returns

string

hex-string with 248 bits max

Example

const result = shortString.encodeShortString("uri/pict/t38.jpg");
// result = "0x7572692f706963742f7433382e6a7067"

Defined in

src/utils/shortString.ts:118


decodeShortString

decodeShortString(str): string

Convert a hexadecimal or decimal string to an ASCII string.

Parameters

NameTypeDescription
strstringrepresenting a 248 bit max number (ex. "0x1A4F64EA56" or "236942575435676423")

Returns

string

short string; 31 characters max

Example

const result = shortString.decodeShortString("0x7572692f706963742f7433382e6a7067");
// result = "uri/pict/t38.jpg"

Defined in

src/utils/shortString.ts:134


isShortText

isShortText(val): boolean

Test if value is short text

Parameters

NameTypeDescription
valanyThe item to test

Returns

boolean

Returns true if the value is a short text (string has less or equal 31 characters), otherwise false

Example

const result = shortString.isShortText("Hello, world!");
// result = true

Defined in

src/utils/shortString.ts:79


isLongText

isLongText(val): boolean

Test if value is long text

Parameters

NameTypeDescription
valanythe value to test

Returns

boolean

returns true if the value is a long text(string has more than 31 characters), otherwise false.

Example

const result = shortString.isLongText("Hello, world! this is some random long string to enable you test isLongText function.");
// result = true

Defined in

src/utils/shortString.ts:91