jComponent / Helpers / String operations
Updated: 26. January 2019
Author: Peter Širka

String operations

Professional Support Chat with contributors

Here is the list of all registered string prototypes in jComponent library:

Method: String.env()

Method reads a value from environments.

// @search {Booelan} enables searching of values in the string
// return {String}

('[key]').env();                  // value 
('Lorem [key] ipsum').env();      // Lorem [key] ipsum 
('Lorem [key] ipsum').env(true);  // Lorem value ipsum 

Method: 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

Method: String.isEmail()

Method checks if the value is valid email address. Regullar expression for email validation is stored in: M.validators.email property.

// return {Boolean}

('your@domain.com').isEmail();  // true
('peter').isEmail();            // false

Method: String.isPhone()

Method checks if the value is valid phone (international) number. Regullar expression for phone validation is stored in: M.validators.phone property.

// return {Boolean}

('+421903163302').isPhone();  // true
('1234').isPhone();           // false

Method: String.isURL()

Method checks if the value is valid URL address. Regullar expression for URL validation is stored in: M.validators.url property.

// return {Boolean}

('https://www.totaljs.com').isURL();  // true
('www.totaljs.com').isURL();          // false

Method: String.padLeft()

Method performs padding.

String.padLeft(count, [char]);
// @count {Number}
// @char {String} optional, default " "
// return {String}

Method: String.padRight()

Method performs padding.

String.padRight(count, [char]);
// @count {Number}
// @char {String} optional, default " "
// return {String}

Method: String.params()

Method peforms a simple formatting.

// @obj {Object}
// return {String}

('My name is {name}.').params({ name: 'Peter' });   // My name is Peter.

Method: String.parseConfig()

Method parses configuration from String.

String.parseConfig([def]. [callback]);
// @def {String/Object} Optional, default values
// @callback {Function(key, value)} Optional
// return {Object}

// Output: { length: 30, name: "Peter", age: 33, required: true }

Method: String.parseDate()

Method parses date from String. It can parses time too.

// 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)

Method: String.parseInt()

Method finds and parses the whole Number.

// @def {Number} optional, default "0"
// return {Number}

('1984').parseInt();    // 1984
('19.84').parseInt();   // 19
('-1984').parseInt();   // -1984
('ABC').parseInt();     // 0
('ABC').parseInt(1);    // 1

Method: String.parseFloat()

Method finds and parses Float.

// @def {Number} optional, default "0"
// return {Number}

('19.84').parseFloat();   // 19.84

Method: String.removeDiacritics()

Method removes diacritics, basic latin + cyrillic.

// return {String}

('ľščťžýáí').removeDiacritics();   // lsctzyai

Method: 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.

Method: String.slug()

Method performs slugify.

// @max {Number} optional, default 60
// return {String}

('Peter Širka').slug();   // peter-sirka

Method: String.toSearch()

Method creates a search phrase.

// return {String}

('Banská Bystrica').toSearch();   // banska bistrica