String utils.
- Source:
Methods
(static) makeClassName(names) → {String}
- Source:
- Since:
- 0.1.5
Utility function to build a CSS class name string.
The function accepts either an Object or an Array.
If you pass an object, then it should have the class names as keys. The resulting class names will be
the keys holding "truthy" values.
"Falsy" values are ""
, 0
, -0
, false
,
null
, NaN
and undefined
.
Example
const obj = { foo: true, bar: false, baz: true };
const arr = ["foo", undefined, "", "foo", "baz"];
makeClassName(obj) // => "foo baz"
makeClassName(arr) // => "foo baz"
makeClassName({}) // => ""
makeClassName([]) // => ""
Parameters:
Name | Type | Description |
---|---|---|
names |
Array.<String> | Object.<String, Boolean> |
Returns:
- Type
- String
(static) makeQuerystring(source) → {String}
- Source:
- Since:
- 0.0.2
Builds a querystring from a plain object. Undefined keys will be skipped.
Example
const song = {
author: "Jethro Tull",
name: "Bourée",
year: undefined
};
makeQuerystring(song) // => "author=Jethro%20Tull&name=Bour%C3%A9e"
Parameters:
Name | Type | Description |
---|---|---|
source |
Object |
Returns:
- Type
- String
(static) stripHTML(source) → {String}
- Source:
- Since:
- 0.0.1
Remove all HTML tags from a string.
Example
const htmlString = "<p>Lorem <strong class=\"foo bar\">ipsum dolor</strong> sit amet</p>";
stripHTML(htmlString) // => "Lorem ipsum dolor sit amet"
Parameters:
Name | Type | Description |
---|---|---|
source |
String |
Returns:
- Type
- String
(static) stripHTMLAttributes(source) → {String}
- Source:
- Since:
- 0.0.1
Remove all HTML attributes from a string containing HTML.
Example
const htmlString = "<p class=\"foo bar\" id=\"main\">Lorem ipsum</p>";
stripHTMLAttributes(htmlString) // => "<p>Lorem ipsum</p>"
Parameters:
Name | Type | Description |
---|---|---|
source |
String |
Returns:
- Type
- String