Namespace: shortString
Functionsβ
isASCIIβ
βΈ isASCII(str
): boolean
Test if string contains only ASCII characters (string can be ascii text)
Parametersβ
Name | Type | Description |
---|---|---|
str | string | The 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β
isShortStringβ
βΈ isShortString(str
): boolean
Test if a string is a Cairo short string (string with less or equal 31 characters)
Parametersβ
Name | Type | Description |
---|---|---|
str | string | the 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β
isDecimalStringβ
βΈ isDecimalString(str
): boolean
Test if string contains only numbers (string can be converted to decimal integer number)
Parametersβ
Name | Type | Description |
---|---|---|
str | string | the 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β
isTextβ
βΈ isText(val
): boolean
Test if value is a pure string text, and not a hex string or number string
Parametersβ
Name | Type | Description |
---|---|---|
val | any | the 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β
splitLongStringβ
βΈ splitLongString(longStr
): string
[]
Split long text (string greater than 31 characters) into short strings (string lesser or equal 31 characters)
Parametersβ
Name | Type | Description |
---|---|---|
longStr | string | the 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β
encodeShortStringβ
βΈ encodeShortString(str
): string
Convert an ASCII short string to a hexadecimal string.
Parametersβ
Name | Type | Description |
---|---|---|
str | string | short 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β
decodeShortStringβ
βΈ decodeShortString(str
): string
Convert a hexadecimal or decimal string to an ASCII string.
Parametersβ
Name | Type | Description |
---|---|---|
str | string | representing 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β
isShortTextβ
βΈ isShortText(val
): boolean
Test if value is short text
Parametersβ
Name | Type | Description |
---|---|---|
val | any | The 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β
isLongTextβ
βΈ isLongText(val
): boolean
Test if value is long text
Parametersβ
Name | Type | Description |
---|---|---|
val | any | the 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