-
Notifications
You must be signed in to change notification settings - Fork 0
WD JS Text Tools
To be considered as text type, the value argument must be a String that does not meet the criteria for defining date, time, number or null (A String without a printable character is considered a null value).
The initial value cannot be modified by methods or attributes.
To find the description of the tools presented in this section, it is recommended that you read the following topics:
wd(text).camel
let a = wd("Stella maris");
a.camel; /* returns "stellaMaris" */
let b = wd("stella-maris");
b.camel; /* returns "Stella Maris" */
wd(text).caps
let a = wd("Stella maris");
a.caps; /* returns "Stella Maris" */
wd(text).clear
let a = wd("Acentuación prosódica y acentuación ortográfica");
a.clear; /* returns "Acentuacion prosodica y acentuacion ortografica" */
wd(text).csv
The columns of the CSV file must be separated by the character \t
and the lines by the character \n
:
Cell00 Cell01 Cell02 Cell03
Cell10 Cell11 Cell12 Cell13
Cell20 Cell21 Cell22 Cell23
Cell30 Cell31 Cell32 Cell33
let a = wd("00\t01\t02\n10\t11\t12");
a.csv; /* returns [["00", "01", "02"], ["10", "11", "12"]] */
wd(text).dash
let a = wd("Stella maris");
a.dash; /* returns "stella-maris" */
let b = wd("stellaMaris");
b.dash; /* returns "stella-maris" */
wd(text).format(attr...)
Argument | Type | Mandatory | Description |
---|---|---|---|
attr |
String | Yes | Name of attributes to call formatting. |
let a = wd("Stella maris");
a.format("dash", "upper"); /* returns "STELLA-MARIS" */
a.format("upper", "dash"); /* returns "s-t-e-l-l-a-m-a-r-i-s" */
If no attribute is given, returns null.
wd(text).json
let j = wd("{\"a\": 1, \"b\": \"unus\"}");
j.json; /* returns {a: 1, b: "unus"} */
wd(text).lower
let a = wd("Stella maris");
a.lower; /* returns "stella maris" */
wd(text).mask(check, callback)
Argument | Type | Mandatory | Description |
---|---|---|---|
check |
String | Yes | Value to be checked by the mask. |
callback |
Function | No | Extra validation function. |
In case of success, it will return a String with the result of applying the mask, otherwise, null
.
The mask encoding is entered as the textual content and has the following options:
Code | RegExp | Description |
---|---|---|
# | [0-9] |
Numerical values. |
@ | [a-zA-ZÀ-ÿ] |
Latin alphabet. |
* | . |
Any character. |
? | None | Mask separator. |
let a = wd("(##) ####-####");
a.mask("4433339999"); /* returns "(44) 3333-9999" */
a.mask("(44) 3333-9999"); /* returns "(44) 3333-9999" */
The mask separator (?) has the function of testing several masks in sequence, if the first one informed does not match, it will test the second one and so on.
let a = wd("(##) ####-####?(##) # ####-####");
a.mask("4433339999"); /* returns "(44) 3333-9999" */
a.mask("44833339999"); /* returns "(44) 8 3333-9999" */
let b = wd("0.0#?0.##?#.##");
b.mask(1); /* returns "0.01" */
b.mask(12); /* returns "0.12" */
b.mask(123); /* returns "1.23" */
The extra check function will receive the matched mask as an argument and should return, depending on the analysis, true for mask validation or false when invalid.
function check(x) {
let value = wd(x);
return value.type === "date" ? true : false;
}
let a = wd("##/##/####");
a.mask("15042010", check); /* returns "15/04/2020" */
a.mask("04152010", check); /* returns null */
let b = wd("##/##/####?##.##.####");
a.mask("04152010", check); /* returns "04.15.2010" */
To use the encoding characters in the mask, you must insert two backslashes (\) before the character, except for the mask separator (?).
let a = wd("#\\# *@@@\\*");
a.mask("1$ABC"); /* returns "1# $ABC*" */
wd(text).rpl(search, change)
Argument | Type | Mandatory | Description |
---|---|---|---|
search |
String | Yes | Value to find and replace. |
change |
String | Yes | Substitute value. |
let a = wd("Stella maris");
a.rpl("MARIS", "Maris"); /* returns "Stella maris" */
a.rpl("maris", "Maris"); /* returns "Stella Maris" */
wd(text).tgl
let a = wd("Stella maris");
a.tgl; /* returns "sTELLA MARIS" */
wd(text).trim
let a = wd(" \t Stella \t \n maris \t ");
a.trim; /* returns "Stella maris" */
wd(text).upper
let a = wd("Stella maris");
a.upper; /* returns "STELLA MARIS" */
- WD Web Libraries | v4.4.4 | 2023-02-22
- Updated on 2023-02-22
- WD JS Array Tools
- WD JS Date Tools
- WD JS DOM Tools
- WD JS Number Tools
- WD JS Text Tools
- WD JS Time Tools
- WD ATTR Chart Tool
- WD ATTR Click Tool
- WD ATTR CSS Tool
- WD ATTR Data Tool
- WD ATTR Device Tool
- WD ATTR Edit Tool
- WD ATTR Filter Tool
- WD ATTR Full Tool
- WD ATTR Jump Tool
- WD ATTR Lang Tool
- WD ATTR Load Tool
- WD ATTR Mask Tool
- WD ATTR Nav Tool
- WD ATTR NoBubbles Tool
- WD ATTR Output Tool
- WD ATTR Page Tool
- WD ATTR Repeat Tool
- WD ATTR Send Tool
- WD ATTR Set Tool
- WD ATTR Shared Tool
- WD ATTR Slide Tool
- WD ATTR Sort Tool
- WD ATTR Tsort Tool
- WD ATTR Translate Tool
- WD ATTR URL Tool
- WD ATTR Vform Tool