Here is the list of all registered string
prototypes in jComponent library:
String.arg(obj, [encode], [def])
String.COMPILABLE()
String.encode()
String.env([search])
String.format([a], [b], [n])
String.isEmail()
String.isPhone()
String.isURL()
String.padLeft(count, [char])
String.padRight(count, [char])
String.params(obj)
String.parseConfig([callback])
String.parseDate()
String.parseFloat([def])
String.parseInt([def])
String.removeDiacritics()
String.render(model, [repository])
String.SCOPE(element)
String.slug([max])
String.toSearch()
String.arg()
+v17
Method replaces {key}
for a obj[key]
.
String.arg(obj, [encode], [def]);
// @obj {Object} A model
// @encode {String/Boolean} performs URL encode for values (optional, can be "json", "escape" or "encode"/true)
// @def {String} optional, a default value (default: undefined)
// return {String}
console.log(('Hello {name}!').arg({ name: 'world' }));
// Hello world!
console.log(('Hello {missing}!').arg({ name: 'world' }));
// Hello {missing}!
console.log(('Hello {missing}!').arg({ name: 'world' }, 'MISSING'));
// Hello MISSING!
String.COMPILABLE()
+v17
Method determines if the string contains some components, data-bind
or something else for compilation. It's targeted for Tangular templates.
String.COMPILABLE();
// return {Boolean}
String.encode()
+v18
Method encodes string to HTML safe characters. Internally it uses Thelpers.encode()
.
String.encode();
// return {String}
String.env()
Method reads a value from environments.
String.env([search]);
// @search {Boolean} enables searching of values in the string
// return {String}
('[key]').env(); // value
('[.key]').env(); // +v17 performs GET('key')
('Lorem [key] ipsum').env(); // Lorem [key] ipsum
('Lorem [key] ipsum').env(true); // Lorem value ipsum
String.format()
Method formats the string.
String.format([a], [b], [n]);
// return {String}
('My name is {0}.').format('Peter'); // My name is Peter.
('{0} {1}').format('Hello', 'World'); // Hello World
String.isEmail()
Method checks if the value is valid email address. Regullar expression for email validation is stored in: M.validators.email
property.
String.isEmail();
// return {Boolean}
('your@domain.com').isEmail(); // true
('peter').isEmail(); // false
String.isPhone()
Method checks if the value is valid phone (international) number. Regullar expression for phone validation is stored in: M.validators.phone
property.
String.isPhone();
// return {Boolean}
('+421903163302').isPhone(); // true
('1234').isPhone(); // false
String.isURL()
Method checks if the value is valid URL address. Regullar expression for URL validation is stored in: M.validators.url
property.
String.isURL();
// return {Boolean}
('https://www.totaljs.com').isURL(); // true
('www.totaljs.com').isURL(); // false
String.padLeft()
Method performs padding.
String.padLeft(count, [char]);
// @count {Number}
// @char {String} optional, default " "
// return {String}
String.padRight()
Method performs padding.
String.padRight(count, [char]);
// @count {Number}
// @char {String} optional, default " "
// return {String}
String.params()
Method peforms a simple formatting.
String.params(obj);
// @obj {Object}
// return {String}
('My name is {name}.').params({ name: 'Peter' }); // My name is Peter.
String.parseConfig()
Method parses configuration from String
.
String.parseConfig([def]. [callback]);
// @def {String/Object} Optional, default values
// @callback {Function(key, value)} Optional
// return {Object}
console.log('name:Peter;age:33;required:true'.parseConfig('length:30'));
// Output: { length: 30, name: "Peter", age: 33, required: true }
String.parseDate()
Method parses date from String
. It can parses time
too.
String.parseDate();
// return {Date}
('1984-12-06').parseDate(); // Thu Dec 06 1984 00:00:00 GMT+0100 (CET)
('06.12.1984').parseDate(); // Thu Dec 06 1984 00:00:00 GMT+0100 (CET)
('06.12.1984 12:00:50').parseDate(); // Thu Dec 06 1984 12:00:50 GMT+0100 (CET)
('12:00').parseDate(); // Current date 12:00:00 GMT+0100 (CET)
('10:00 PM').parseDate(); // +v17 Current date 22:00:00 GMT+0100 (CET)
String.parseInt()
Method finds and parses the whole Number
.
String.parseInt([def]);
// @def {Number} optional, default "0"
// return {Number}
('1984').parseInt(); // 1984
('19.84').parseInt(); // 19
('-1984').parseInt(); // -1984
('ABC').parseInt(); // 0
('ABC').parseInt(1); // 1
String.parseFloat()
Method finds and parses Float
.
String.parseFloat([def]);
// @def {Number} optional, default "0"
// return {Number}
('19.84').parseFloat(); // 19.84
String.removeDiacritics()
Method removes diacritics, basic latin + cyrillic.
String.removeDiacritics();
// return {String}
('ľščťžýáí').removeDiacritics(); // lsctzyai
String.render()
Method performs Tangular.render()
.
String.render(model, [repository]);
// @model {Object}
// @repository {Object} optional
// return {String}
('My name is {{ name }}.').render({ name: 'Peter' }); // My name is Peter.
String.SCOPE()
v17
Method returns a path according to the element scope.
String.SCOPE(element);
// @element {Component/Scope/jQuery/Element/Plugin} Important!!!
// return {String}
('?.name').SCOPE($('[data---]')); // user.name
// self === jComponent
('?.name').SCOPE(self); // user.name
String.slug()
Method performs slugify.
String.slug(max);
// @max {Number} optional, default 60
// return {String}
('Peter Širka').slug(); // peter-sirka
String.toSearch()
Method creates a search phrase.
String.toSearch();
// return {String}
('Banská Bystrica').toSearch(); // banska bistrica