Skip to main content

LazyWrapper

lazy-engine / Exports / LazyWrapper

Class: LazyWrapper

A chainable data manipulation library for SlothTools.

All methods will modify the value stored inside the Lazy Object and return this Lazy Object, to allow contuined chaining, except...

  • .clone()
  • .valueOf()
  • .typeOf()
  • .get()

Example

Lazy([ "20", "234", "ABC", "19.312" ])
.parseInt() // Lazy([ 20, 234, "ABC", 19 ])
.add(3) // Lazy([ 23, 237, "ABC3", 22 ])
.pop() // Lazy([ 23, 237, "ABC3" ])
.push(10) // Lazy([ 23, 237, "ABC3", 10 ])
.remove(-2) // Lazy([ 23, 237, 10 ])
.sum() // Lazy(270)
.valueOf() // 270

Table of contents

Constructors

Properties

Array Methods

Array + String Methods

Export Methods

Format Methods

Import Methods

Number Methods

Object Methods

Other Methods

Primitive Methods

String Methods

Constructors

constructor

new LazyWrapper(content)

Constructor of Lazy Object

Example

Lazy(20)        // Lazy(20).valueOf() = 20;
Lazy(Lazy(20)) // Lazy(20).valueOf() = 20;
Lazy([1, 2, 3]) // Lazy([1, 2, 3]).valueOf() = [1, 2, 3];
Lazy("Hello!") // Lazy("Hello!").valueOf() = "Hello!";

Parameters

NameTypeDescription
contentValue | LazyWrapper{any|Lazy} the content value of the Lazy Object

Properties

vtype

Private vtype: Type = Type.String


value

Private value: Value = ""

Array Methods

filter

filter(predicate): LazyWrapper

The filter method removes all elements in the array which do not pass the predicate function, if the predicate returns true for a specific element that element in the array is kept.

Example

Lazy([1, 2, 3, 4]).filter((elm) => { return elm.valueOf() % 2 == 0 })  // Lazy([2, 4])
Lazy(["a", "b", "c"]).filter(elm => { return elm.valueOf() == "b" }) // Lazy(["b"])

Parameters

NameTypeDescription
predicate(value: LazyWrapper, index?: number, array?: Value[]) => anyfunction should return a truthy for the element to be kept in the array. Paramaters of the predicate are as follows - value: Lazy value - current element being validated - index: number - current index of the element being validated - array: any[] - a list of all elements in the array being filtered

Returns

LazyWrapper

this Lazy Object with updated value, any[] → any[]


map

map(callbackfn, thisArg?): LazyWrapper

The map method replaces every element based on functions return value.

Example

Lazy([1, 2, 3]).map((elm) => { return elm.valueOf() + 1 })  // Lazy([2, 3, 4])
Lazy(["a", "b"]).map(elm => { elm.add("!") }) // Lazy(["a!", "b!"])
Lazy([ { "name": 2 }, { "name": 3 } ]).map("name") // Lazy([2, 3])

Parameters

NameTypeDescription
callbackfnString | (value: LazyWrapper, index?: number, array?: Value[]) => undefined | Value | LazyWrapperfunction should return the value the element; if set to string will extract that key from every object should be mapped to. You may either return a new value or update the lazy object value directory. - value: Lazy value - current element being mapped - index: number - current index of the element being mapped - array: any[] - a list of all elements in the array being filtered
thisArg?any-

Returns

LazyWrapper

this Lazy Object with updated value, any[] → any[]


reverse

reverse(): LazyWrapper

The reverse method reverses the order of the array

Example

Lazy([1, 2, 3]).reverse()       // Lazy([3, 2, 1])
Lazy(["a", "b", "c"]).reverse() // Lazy(["c", "b", "a"])

Returns

LazyWrapper

this Lazy Object with updated value, any[] → any[]


sort

sort(compareFn?): LazyWrapper

The sort method sorts elements in an array based on the difference between the two numbers.

Example

Lazy([2, 3, 1]).sort()                                                     // Lazy([1, 2, 3])
Lazy(["b", "c", "a"]).sort((a, b) => { return a.valueOf() - b.valueOf() }) // Lazy(["a", "b", "c"])
Lazy(["b", "c", "a"]).sort((a, b) => { return b.valueOf() - a.valueOf() }) // Lazy(["c", "b", "a"])

Parameters

NameTypeDescription
compareFn?(a: LazyWrapper, b: LazyWrapper) => numberfunction should return an integer value - a: Lazy value - first element for comparison - b: Lazy value - second element for comparison

Returns

LazyWrapper

this Lazy Object with updated value, any[] → any[]


fromEntries

fromEntries(): LazyWrapper

The fromEntries method transforms a list of key-values pairs into an object

Example

Lazy([["foo", 2], ["bar", 3]]).fromEntries() // Lazy({ "foo": 2, "bar": 3 })
Lazy(["foo", [1, 2, 3]]).fromEntries() // Lazy({ "foo": [1, 2, 3] })

Returns

LazyWrapper

this Lazy Object with updated value, any[][] → object


random

random(): LazyWrapper

The random method selects a random item from an array. It is recommended that you clone the object before performing this method, becuase it will replace the object witht the randomly selecte element.

Example

Lazy([1, 2, 3, 4, 5]).clone().random() // Lazy(2)
Lazy([1, 2, 3, 4, 5]).clone().random() // Lazy(1)
Lazy([1, 2, 3, 4, 5]).clone().random() // Lazy(5)

Returns

LazyWrapper

this Lazy Object with updated value, any[] → any


join

join(seperator?): LazyWrapper

The join method will join all elements in an array with a string seperator or by default a comma. If the array has only one item, then that item will be returned without using the separator.

Example

Lazy([1, 2, 3, 4, 5]).join()    // Lazy("1,2,3,4,5")
Lazy([1, 2, 3, 4, 5]).join("") // Lazy("12345")
Lazy(["a", "b", "c"]).join("-") // Lazy("a-b-c")
Lazy(["hello world"]).join("-") // Lazy("hello world")

Parameters

NameType
seperator?string

Returns

LazyWrapper

this Lazy Object with updated value, any[] → any


transverse

transverse(fnc?, initial?): LazyWrapper

The transverse method recurse the length of the array storing a payload that can be updated as you tansverse the array. The value returned by the transverse function will be the payload for the next element. By default the function is sums for more information.

Example

Lazy([1, 2, 3, 4, 5]).transverse((item, payload, index) => { return payload.multiply(item) }) // Lazy(120)
Lazy([1, 2, 3, 4, 5]).transverse((item, payload, index) => { return payload.add(index) }) // Lazy(10)
Lazy(1, 2, 3).transverse() // Lazy(5)

Parameters

NameTypeDefault valueDescription
fnc?(item: LazyWrapper, payload: LazyWrapper, index?: number) => anyundefinedfunction that produces the next payload - item: Lazy value - current element - payload: Lazy value - current payload value - index?: number - is the index value of the current element
initialValue0starting value for the payload

Returns

LazyWrapper

this Lazy Object with updated value, any[] → any


sum

sum(): LazyWrapper

The sum method add all elements togeather across the array.

Example

Lazy([1, 2, 3, 4, 5]).sum() // Lazy(25)
Lazy(["a", "b", "c"]).sum() // Lazy("abc")

Returns

LazyWrapper

this Lazy Object with updated value, any[] → any


hashify

hashify(key): LazyWrapper

The hashify method will convert an array of object into a hashmap using a selected attribute of the objects in the array, as the key for the hashmap.

Example

Lazy([
{ "id": "a", "name": "Evan" },
{ "id": "b", "name": "Reilly" }
]).hashify("id")
// Lazy({
// "a": { "id": "a", "name": "Evan" },
// "b": { "id": "b", "name": "Reilly" }
// })

Parameters

NameTypeDescription
keystringfrom each object to be used as key for the hashmap

Returns

LazyWrapper

this Lazy Object with updated value, object[] → object


toEntries

toEntries(): LazyWrapper

The toEntries method transforms a object into list of key-values pairs

Example

Lazy({ "foo": 2, "bar": 3 }).toEntries() // Lazy([["foo", 2], ["bar", 3]])
Lazy({ "foo": [1, 2, 3] }).toEntries() // Lazy(["foo", [1, 2, 3]])

Returns

LazyWrapper

this Lazy Object with updated value, object → any[][]


unhashify

unhashify(key): LazyWrapper

The unhashify method will convert an hashmap of objects into an array using a selected "key" value.

Example

Lazy({
"a": { "id": "a", "name": "Evan" },
"b": { "id": "b", "name": "Reilly" }
}).unhashify("id")
// Lazy([
// { "id": "a", "name": "Evan" },
// { "id": "b", "name": "Reilly" }
// ])

Parameters

NameTypeDescription
keystringfrom each object to be used as key for the hashmap

Returns

LazyWrapper

this Lazy Object with updated value, object → object[]


Array + String Methods

slice

slice(indexStart, indexEnd?): LazyWrapper

The slice method keeps only the elments of the array/string from the start index up-to and excluding the end index. Use negative index values to index from the end of the array/string.

Example

Lazy([ 1, 2, 3, 4 ]).slice(1)     // Lazy([ 2, 3, 4 ])
Lazy([ 1, 2, 3, 4 ]).slice(1, 3) // Lazy([ 2, 3 ])
Lazy([ 1, 2, 3, 4 ]).slice(1, -1) // Lazy([ 2, 3 ])
Lazy("abcd").slice(1) // Lazy("bcd")
Lazy("abcd").slice(1, 3) // Lazy("bc")
Lazy("abcd").slice(1, -1) // Lazy("bc")

Parameters

NameTypeDescription
indexStartnumberthe first element/character to be included in the array/string
indexEnd?numberthe first element/character to be excluded in the array/string

Returns

LazyWrapper

this Lazy Object with updated value, String → String, any[] → any[]


concat

concat(item): LazyWrapper

The concat method appends an array/string on to an array/string.

Example

Lazy([ 1, 2, 3, 4 ]).concat([ 5, 6 ]) // Lazy([ 1, 2, 3, 4, 5, 6 ])
Lazy("abcd").slice("ef") // Lazy("abcdef")

Parameters

NameTypeDescription
itemstring | Value[]the array/string to be concatenated on to the array/string

Returns

LazyWrapper

this Lazy Object with updated value, String → String, any[] → any[]


push

push(item): LazyWrapper

The push method appends an element onto the end of a string/array.

Example

Lazy([ 1, 2, 3, 4 ]).push(5) // Lazy([ 1, 2, 3, 4, 5 ])
Lazy("abcd").push("ef") // Lazy("abcdef")

Parameters

NameTypeDescription
itemValuethe element to be appended to the array/string

Returns

LazyWrapper

this Lazy Object with updated value, String → String, any[] → any[]


pop

pop(): LazyWrapper

The pop method removes the last element off of a string/array. The popped value is not obtainble after popping. To obtain the last value store .get(-1) and then .pop().

Example

Lazy([ 1, 2, 3, 4 ]).pop() // Lazy([ 1, 2, 3 ])
Lazy("abcd").pop() // Lazy("abc")

Returns

LazyWrapper

this Lazy Object with updated value, String → String, any[] → any[]


insert

insert(item, index?): LazyWrapper

The insert method inserts an item in and array/string based on index, by default inserting at index 0. Use negative index values to index from the end of the array/string.

Example

Lazy([ 1, 2, 3, 4 ]).insert(0)       // Lazy([ 0, 1, 2, 3, 4 ])
Lazy([ 1, 2, 3, 4 ]).insert(2.5 , 2) // Lazy([ 1, 2, 2.5, 3, 4 ])
Lazy([ 1, 2, 3, 4 ]).insert(5, -1) // Lazy([ 1, 2, 3, 4, 5 ])
Lazy("abcd").insert("!") // Lazy("!abcd")
Lazy("abcd").insert("!" , 2) // Lazy("ab!cd")
Lazy("abcd").insert("!", -1) // Lazy("abcd!")

Parameters

NameTypeDefault valueDescription
itemValueundefinedto be inserted
indexnumber0the item will be inserted at

Returns

LazyWrapper

this Lazy Object with updated value, String → String, any[] → any[]


remove

remove(index?): LazyWrapper

The remove method remove an item in an array/string based on index, by default removing at index 0. Use negative index values to index from the end of the array/string.

Example

Lazy([ 1, 2, 3, 4 ]).remove()   // Lazy([ 0, 1, 2, 3, 4 ])
Lazy([ 1, 2, 3, 4 ]).remove(2) // Lazy([ 1, 2, 3, 4 ])
Lazy([ 1, 2, 3, 4 ]).remove(-1) // Lazy([ 1, 2, 3 ])
Lazy("abcd").remove() // Lazy("bcd")
Lazy("abcd").remove(2) // Lazy("abd")
Lazy("abcd").remove(-1) // Lazy("abc")

Parameters

NameTypeDefault valueDescription
indexnumber0the item will be removed at

Returns

LazyWrapper

this Lazy Object with updated value, String → String, any[] → any[]


length

length(): LazyWrapper

The length method gets the length of an array/string. It is recommend you clone the object before getting the length, as the length number will replace the object.

Example

Lazy([]).clone().length()             // Lazy(0)
Lazy([ 1, 2 ]).clone().length() // Lazy(2)
Lazy([ 1, 2, 3, 4 ]).clone().length() // Lazy(4)
Lazy("").clone().length() // Lazy(0)
Lazy("ab").clone().length() // Lazy(2)
Lazy("abcd").clone().length() // Lazy(4)

Returns

LazyWrapper

this Lazy Object with updated value, String → number, any[] → number


Export Methods

exportJSON

exportJSON(): LazyWrapper

The exportJSON method will convert an object to a JSON formated string.

Example

Lazy({ "foo": 2 }).exportJSON()   // Lazy("{ \"foo\": 2 }")

Returns

LazyWrapper

this Lazy Object with updated value, object → string


exportYAML

exportYAML(): LazyWrapper

The exportYAML method will convert an object to a YAML formated string.

Example

Lazy({ "foo": 2 }).exportYAML()   // Lazy("foo: 2")

Returns

LazyWrapper

this Lazy Object with updated value, object → string


exportCSV

exportCSV(delimiter?): LazyWrapper

The exportCSV method will convert an array of objects to a CSV formated string. That the first line of the text is title of the columns.

Example

Lazy([{ "name": "foo", "number": 2 }]).exportCSV()     // Lazy("name,number\nfoo,2")
Lazy([{ "name": "foo", "number": 2 }]).exportCSV("\t") // Lazy("name number\nfoo 2")

Parameters

NameTypeDefault valueDescription
delimiterstring","the seperator for each element in the CSV file

Returns

LazyWrapper

this Lazy Object with updated value, object[] → string


exportExcel

exportExcel(): LazyWrapper

The exportExcel method will export an array of objects as a spreadsheet format (CSV w/ tabulation as delimiter) that is copy and pasted from an Microsoft Excel or other spreadsheet application.

Example

Lazy([{ "name": "foo", "number": 2 }]).exportExcel() // Lazy("name   number\nfoo    2")

Returns

LazyWrapper

this Lazy Object with updated value, string → object[]


exportXML

exportXML(): LazyWrapper

The exportXML method will export XML/HTML data and convert it to a JSON data format. This accepts both a compact and non-compact format.

Example

Lazy({"root":{"test":["AB1","AB2"]}}).exportXML()                                                                       // Lazy("<root><test>AB1</test><test>AB2</test></root>")
Lazy({"root":{"test":[{"_attributes":{"id":"1"},"_text":"AB1"},{"_attributes":{"id":"2"},"_text":"AB2"}]}}).exportXML() // Lazy("<root><test id="1">AB1</test><test id="2">AB2</test></root>")

Returns

LazyWrapper

this Lazy Object with updated value, object → string


Format Methods

beautifyJavascript

beautifyJavascript(): LazyWrapper

The beautifyJavascript method will deobfuscate javascript code to make the code readable by adding back whitespace. The reverse of this process obfuscate can be done using the minifyJavascript method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifyCSS

beautifyCSS(): LazyWrapper

The beautifyCSS method will deobfuscate CSS code to make the code readable by adding back whitespace. The reverse of this process obfuscate can be done using the minifyJavascript method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifyJSON

beautifyJSON(): LazyWrapper

The beautifyJSON method will deobfuscate JSON code to make the code readable by adding back whitespace. The reverse of this process obfuscate can be done using the minifyJSON method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifyHTML

beautifyHTML(): LazyWrapper

The beautifyHTML method will deobfuscate HTML code to make the code readable by adding back whitespace. The reverse of this process obfuscate can be done using the minifyHTML method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifyXML

beautifyXML(): LazyWrapper

The beautifyXML method will deobfuscate XML code to make the code readable by adding back whitespace. The reverse of this process obfuscate can be done using the minifyXML method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifyYAML

beautifyYAML(): LazyWrapper

The beautifyYAML method will deobfuscate YAML code to make the code readable by adding back whitespace.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifyTypescript

beautifyTypescript(): LazyWrapper

The beautifyTypescript method will deobfuscate TypeScript code to make the code readable by adding back whitespace.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifyJava

beautifyJava(): LazyWrapper

The beautifyJava method will deobfuscate Java code to make the code readable by adding back whitespace.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifySCSS

beautifySCSS(): LazyWrapper

The beautifySCSS method will deobfuscate SCSS code to make the code readable by adding back whitespace.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifyLESS

beautifyLESS(): LazyWrapper

The beautifyLESS method will deobfuscate LESS code to make the code readable by adding back whitespace.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


beautifySQL

beautifySQL(): LazyWrapper

The beautifySQL method will deobfuscate SQL code to make the code readable by adding back whitespace.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


minifyJavascript

minifyJavascript(): LazyWrapper

The minifyJavascript method will obfuscate Javascript code to make the code small, but reduce readability by removing whitespace. The reverse of this process deobfuscate can be done using the beautifyJavascript method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


minifyCSS

minifyCSS(): LazyWrapper

The minifyCSS method will obfuscate CSS code to make the code small, but reduce readability by removing whitespace. The reverse of this process deobfuscate can be done using the beautifyCSS method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


minifyJSON

minifyJSON(): LazyWrapper

The minifyJSON method will obfuscate JSON code to make the code small, but reduce readability by removing whitespace. The reverse of this process deobfuscate can be done using the beautifyJSON method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


minifyHTML

minifyHTML(): LazyWrapper

The minifyHTML method will obfuscate HTML code to make the code small, but reduce readability by removing whitespace. The reverse of this process deobfuscate can be done using the beautifyHTML method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


minifyXML

minifyXML(): LazyWrapper

The minifyXML method will obfuscate XML code to make the code small, but reduce readability by removing whitespace. The reverse of this process deobfuscate can be done using the beautifyXML method.

Returns

LazyWrapper

this Lazy Object with updated value, string → string


Import Methods

importJSON

importJSON(): LazyWrapper

The importJSON method will convert a JSON formated string to an object.

Example

Lazy("{ \"foo\": 2 }").importJSON()   // Lazy({ "foo": 2 })

Returns

LazyWrapper

this Lazy Object with updated value, string → object


importYAML

importYAML(): LazyWrapper

The importYAML method will convert a YAML formated string to an object.

Example

Lazy("foo: 2").importYAML()   // Lazy({ "foo": 2 })

Returns

LazyWrapper

this Lazy Object with updated value, string → object


importCSV

importCSV(delimiter?): LazyWrapper

The importCSV method will convert a CSV formated string to an array of object. Ensure that the first line of the text is title of the columns.

Example

Lazy("name,number\nfoo,2").importCSV()          // Lazy([{ "name": "foo", "number": 2 }])
Lazy("name number\nfoo 2").importCSV("\t") // Lazy([{ "name": "foo", "number": 2 }])

Parameters

NameTypeDefault valueDescription
delimiterstring","the seperator for each element in the CSV file

Returns

LazyWrapper

this Lazy Object with updated value, string → object[]


importExcel

importExcel(): LazyWrapper

The importExcel method will import the spreadsheet format (CSV w/ tabulation as delimiter) that is copy and pasted from an Microsoft Excel or other spreadsheet application to an array of objects.

Example

Lazy("name   number\nfoo    2").importExcel() // Lazy([{ "name": "foo", "number": 2 }])

Returns

LazyWrapper

this Lazy Object with updated value, string → object[]


importXML

importXML(isCompact?): LazyWrapper

The importXML method will import XML/HTML data and convert it to a JSON data format. By default the conversion is compact which means attributes, comments, and declarations are stripped away.

Example

Lazy("<root><test id="1">AB1</test><test id="2">AB2</test></root>").importXML() // Lazy({"root":{"test":["AB1","AB2"]}})
Lazy("<root><test id="1">AB1</test><test id="2">AB2</test></root>").importXML(false) // Lazy({"root":{"test":[{"_attributes":{"id":"1"},"_text":"AB1"},{"_attributes":{"id":"2"},"_text":"AB2"}]}})

Parameters

NameTypeDefault valueDescription
isCompactbooleantrueif true will strip attributes, comments, and declarations

Returns

LazyWrapper

this Lazy Object with updated value, string → object


Number Methods

max

max(value): LazyWrapper

The max method sets the value to the larger number between the value and paramater.

Example

Lazy(29).max(213)      // Lazy(213)
Lazy(-3.14).max(-3.28) // Lazy(-3.14)
Lazy([3, 9, 7]).max(6) // Lazy([6, 9, 7])

Parameters

NameTypeDescription
valuenumbernumber among which the largest value will be selected

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


min

min(value): LazyWrapper

The min method sets the value to the smallest number between the value and paramater.

Example

Lazy(29).min(213)      // Lazy(29)
Lazy(-3.14).min(-3.28) // Lazy(-3.28)
Lazy([3, 9, 7]).min(6) // Lazy([3, 6, 6])

Parameters

NameTypeDescription
valuenumbernumber among which the smallest value will be selected

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


clamp

clamp(min, max): LazyWrapper

The clamp method clamps the value within the minimum and maximum clamp bounds.

Example

Lazy(29).clamp(9,30)         // Lazy(29)
Lazy(-3.14).clamp(-1.01, 20) // Lazy(-1.01)
Lazy([3, 9, 7]).clamp(4, 8) // Lazy([4, 8, 7])

Parameters

NameTypeDescription
minnumberminimum value is the smallest (most negative) value
maxnumbermaximum value is the largest (most positive) value

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


floor

floor(): LazyWrapper

The floor method rounds down the value

Example

Lazy(29.3).floor()            // Lazy(29)
Lazy(-5.05).floor() // Lazy(-6)
Lazy([5.09, 9.21, 7]).floor() // Lazy([5, 9, 7])

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


ceil

ceil(): LazyWrapper

The ceil method rounds up the value

Example

Lazy(29.3).floor()            // Lazy(30)
Lazy(-5.05).floor() // Lazy(-5)
Lazy([5.09, 9.21, 7]).floor() // Lazy([6, 10, 7])

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


round

round(): LazyWrapper

The round method rounds the value of a number rounded to the nearest integer.

Example

Lazy(29.3).round()              // Lazy(30)
Lazy(-5.05).round() // Lazy(-5)
Lazy([5.95, 5.5, 5.05]).round() // Lazy([6, 6, 5])

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


abs

abs(): LazyWrapper

The abs method takes the absolute value of the value

Example

Lazy(29.3).abs()                // Lazy(29.3)
Lazy(-5.05).abs() // Lazy(5.05)
Lazy([-5.95, 5.5, -5.05]).abs() // Lazy([5.95, 5.5, 5.05])

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


add

add(num): LazyWrapper

The add method adds a number to the current value.

Example

Lazy(29.3).add(2)                 // Lazy(31.3)
Lazy(-5.05).add(-2) // Lazy(-7.05)
Lazy([-5.95, 5.5, -5.05]).add(-1) // Lazy([-6.95, 4.5, -6.05])

Parameters

NameTypeDescription
numnumbernumber added to the current value

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


sub

sub(subtrahend): LazyWrapper

The sub method subtracts a number from the current value.

Example

Lazy(29.3).sub(2)                 // Lazy(27.3)
Lazy(-5.05).sub(-2) // Lazy(-3.05)
Lazy([-5.95, 5.5, -5.05]).sub(-1) // Lazy([-4.95, 4.5, -4.05])

Parameters

NameTypeDescription
subtrahendnumbernumber subtracted from the current value

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


multiply

multiply(num): LazyWrapper

The multiply method multiplies a number by the current value.

Example

Lazy(29.3).multiply(2)                 // Lazy(58.6)
Lazy(-5.05).multiply(-2.5) // Lazy(12.625)
Lazy([-5.95, 5.5, -5.05]).multiply(2) // Lazy([-11.9, 11.0, -10.10])

Parameters

NameTypeDescription
numnumbernumber multiplied by the current value

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


divide

divide(divisor): LazyWrapper

The divide method divides the current value by a divsor number.

Example

Lazy(16).divide(2)                   // Lazy(8)
Lazy(8).divide(-2) // Lazy(-4)
Lazy([-5.95, 5.5, -5.05]).divide(-1) // Lazy([5.95, -5.5, 5.05])

Parameters

NameTypeDescription
divisornumbernumber divided by the current value

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


pow

pow(exponent): LazyWrapper

The pow method takes the current value to the power of an exponent.

Example

Lazy(2).pow(3)          // Lazy(8)
Lazy(4).pow(-2) // Lazy(2)
Lazy([2, 4, -8]).pow(2) // Lazy([4, 16, 64])

Parameters

NameTypeDescription
exponentnumberexponent to apply to current value

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


mod

mod(modulo): LazyWrapper

The mod method takes the modulos of the current value.

Example

Lazy(2).mod(3)         // Lazy(2)
Lazy(4).mod(2) // Lazy(0)
Lazy([9, 5, 7]).mod(3) // Lazy([0, 2, 1])

Parameters

NameTypeDescription
modulonumbermodulos number

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


toFixed

toFixed(digits?): LazyWrapper

The toFixed method formats the current number using fixed-point notation as a string.

Example

Lazy(123.456).toFixed(1)           // Lazy("123.4")
Lazy(0.004).toFixed(2) // Lazy("0.00")
Lazy([-9.2, 0.2, 7.23]).toFixed(0) // Lazy(["-9", "0", "7"])

Parameters

NameTypeDescription
digits?numberThe number of digits to appear after the decimal point; should be a value between 0 and 100, inclusive. If this argument is omitted, it is treated as 0.

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


toPrecision

toPrecision(precision?): LazyWrapper

The toPrecision method formats the current number using fspecified precision notation as a string.

Example

Lazy(123.456).toPrecision(1)           // Lazy("100")
Lazy(0.004).toPrecision(4) // Lazy("0.0040")
Lazy([-9.300, 8.2, 19]).toPrecision(3) // Lazy(["-9.30", "8.20", "19.0"])

Parameters

NameTypeDescription
precision?numberAn integer specifying the number of significant digits

Returns

LazyWrapper

this Lazy Object with updated value, Number → Number, Number[] → Number[]


Object Methods

keys

keys(): LazyWrapper

The keys method gets an array of all keys present in the object

Example

Lazy({ "foo": 1, "bar": 2 }).keys()      // Lazy([ "foo", "bar" ])
Lazy({ "foo": 1, "bar": [2, 3] }).keys() // Lazy([ "foo", "bar" ])

Returns

LazyWrapper

this Lazy Object with updated value, object → string[]


values

values(): LazyWrapper

The values method gets an array of all values present in the object

Example

Lazy({ "foo": 1, "bar": 2 }).values()      // Lazy([ 1, 2 ])
Lazy({ "foo": 1, "bar": [2, 3] }).values() // Lazy([ 1, [ 2, 3 ] ])

Returns

LazyWrapper

this Lazy Object with updated value, object → any[]


mapKeys

mapKeys(callbackfn, thisArg?): LazyWrapper

The mapKeys method replaces each key in the object

Example

Lazy({ "foo": 1, "bar": 2 }).mapKeys((value, index, array) => {
return value.valueOf() + "-" + index;
}); // Lazy({ "foo-0": 1, "bar-1": 2 })

Lazy({ "foo": 1, "bar": [2, 3] }).mapKeys((value, index, array) => {
return value.add(2);
}); // Lazy({ "foo2": 1, "bar2": [2, 3] })

Parameters

NameTypeDescription
callbackfn(value: LazyWrapper, index?: number, array?: Value[]) => undefined | Value | LazyWrapperfunction should return the value the key should be mapped to. You may either return a new value or update the lazy object value directory. - value: Lazy value - current key being mapped - index: number - current index of the key being mapped - array: any[] - a list of all key in the array being mapped
thisArg?any-

Returns

LazyWrapper

this Lazy Object with updated value, object → any[]


mapValues

mapValues(callbackfn, thisArg?): LazyWrapper

The mapValues method replaces each value in the object

Example

Lazy({ "foo": 1, "bar": 2 }).mapValues((value, index, array) => {
return value.valueOf() + "-" + index;
}); // Lazy({ "foo": "1-0", "bar": "2-1" })
Lazy({ "foo": 1, "bar": [2, 3] }).mapValues((value, index, array) => {
return value.add(2);
}); // Lazy({ "foo": 3, "bar2": [4, 5] })

Parameters

NameTypeDescription
callbackfn(value: LazyWrapper, index?: number, array?: Value[]) => undefined | Value | LazyWrapperfunction should return the value the key should be mapped to. You may either return a new value or update the lazy object value directory. - value: Lazy value - current values being mapped - index: number - current index of the values being mapped - array: any[] - a list of all values in the array being mapped
thisArg?any-

Returns

LazyWrapper

this Lazy Object with updated value, object → any[]


Other Methods

getRecursive

Static Private getRecursive(value, ...key): LazyWrapper

Parameters

NameType
valueLazyWrapper
...key(string | number)[]

Returns

LazyWrapper


setRecursive

Static Private setRecursive(value, content, ...key): LazyWrapper

Parameters

NameType
valueLazyWrapper
contentValue
...key(string | number)[]

Returns

LazyWrapper


apply

Private apply(name, type, map, op): LazyWrapper

Parameters

NameType
namestring
typeType
mapboolean
op(val: Value) => Value

Returns

LazyWrapper


applyMap

Private applyMap(name, type, map, op): Value[]

Parameters

NameType
namestring
typeType
mapboolean
op(val: Value) => Value

Returns

Value[]


interpolation

Static interpolation(targetInput, targetOutput, entries): string[] | Object[]

The interpolation method will use smart interpolation to transform entries. Give it a list of inputs, target outputs, and the rest of the entries. It will then transform the rest of the entries.

Parameters

NameTypeDescription
targetInputstring[] | Object[]the target inputs
targetOutputstring[] | Object[]the target outputs
entriesstring[] | Object[]the additional entries to transform

Returns

string[] | Object[]

string[] or Object[] all the entries converted


Primitive Methods

clone

clone(): LazyWrapper

The clone method, will copy the lazy object and it's data. This allows you to execute methods on an object without effecting the original object.

Does not modify this object, returns new object

Example

foo = Lazy([1, 2, 3, 4])
bar = foo.clone().sum()
foo.add(1); // Lazy([2, 3, 4, 5])
bar.add(1); // Lazy(11)

Returns

LazyWrapper

new Lazy Object, with same value and type


get

get(...key): LazyWrapper

The get method, will get a specific index on a string/array or a specific key on an object. Use negative index to start indexing from the end of the array/string.

Does not modify this object, returns new object

Example

Lazy([1, 2, 3, 4]).get(0)          // Lazy(0)
Lazy([1, 2, 3, 4]).get(-1) // Lazy(4)
Lazy("abcd").get(0) // Lazy("a")
Lazy("abcd").get(-1) // Lazy("d")
Lazy({ "foo": 2 }).get("foo") // Lazy(2)
Lazy({ "foo": [2] }).get("foo", 0) // Lazy(2)
Lazy({ "foo": [2] }).get("boo") // Lazy({ "foo": [2] })

Parameters

NameType
...key(string | number)[]

Returns

LazyWrapper

new Lazy Object, with value of object get, any[] → any, object → any, string → string


set

set(content, ...key): LazyWrapper

The set method, will set a specific index on a string/array or a specific key on an object. Use negative index to start indexing from the end of the array/string.

Example

Lazy([1, 2, 3, 4]).set(3)                 // Lazy(3)
Lazy([1, 2, 3, 4]).set("!", 0) // Lazy(["!", 2, 3, 4])
Lazy([1, 2, 3, 4]).set("!", -1) // Lazy([1, 2, 3, "!"])
Lazy("abcd").set("!", 0) // Lazy("!bcd")
Lazy("abcd").set("!", -1) // Lazy("abc!")
Lazy({ "foo": 2 }).set("!", "foo") // Lazy({ "foo": "!" })
Lazy({ "foo": [1,2] }).set("!", "foo", 0) // Lazy({ "foo": ["!",2] })

Parameters

NameTypeDescription
contentValuethe new value to set to
...key(string | number)[]-

Returns

LazyWrapper

this Lazy Object, with same value and type, any[] → any[], object → object, string → string


valueOf

valueOf(): any

The valueOf method returns the raw values stored in the Lazy object.

Does not modify this object, returns raw value stored in object

Example

Lazy(2).valueOf()   // 2
Lazy([3]).valueOf() // [3]
Lazy("!").valueOf() // "!"

Returns

any

raw value stored in object


typeOf

typeOf(): Type

The typeOf method returns the type of the raw values stored in the Lazy object.

Does not modify this object, returns type of the raw value stored in object

Example

Lazy(2).typeOf()             // Type.Number
Lazy("hello world").typeOf() // Type.String
Lazy({ "foo": 2 }).typeOf() // Type.Object
Lazy([ 1, 2, 3 ]).typeOf() // Type.Array

Returns

Type

Type of the raw value stored in object


toString

toString(): LazyWrapper

The toString method exports the current value in the format of a string.

Example

Lazy(2).toString()            // "2"
Lazy({ "foo": 2 }).toString() // "{ \"foo\": 2 }"
Lazy("foo").toString() // "foo"
Lazy([ 1, 2, 3 ]).toString() // "[1,2,3]"

Returns

LazyWrapper

this Lazy Object with updated value, any → string


thru

thru(fnc): LazyWrapper

The thru method allows you to pass the current value to a lambda function and manipulate in any way required. The value returned by the lambda function can be either a raw value or a Lazy Object, and will be the new value.

Example

Lazy(2).thru((payload) => {
return payload.valueOf() + 10;
}); // Lazy(20)

Lazy(2).thru((payload) => {
return payload.multiply(10);
}); // Lazy(20)

Parameters

NameTypeDescription
fnc(payload: any) => Value | LazyWrapperthe lambda function that is called, returned value is the new object value - payload:any - is the current value

Returns

LazyWrapper

this Lazy Object with updated value, any → any


String Methods

parseInt

parseInt(radix?): LazyWrapper

The parseInt method parses a valid string into the integer number the string represents, leading whitespace is ignored.

Example

Lazy("123").parseInt()              // Lazy(123)
Lazy("1.32").parseInt() // Lazy(1)
Lazy("FF").parseInt(16) // Lazy(255)
Lazy(["-9", "8.2", "3"]).parseInt() // Lazy([-9, 8, 3])

Parameters

NameTypeDescription
radix?numberinteger between 2 and 36 that represents the radix of the number system for the number

Returns

LazyWrapper

this Lazy Object with updated value, String → Number, String[] → Number[]


parseFloat

parseFloat(): LazyWrapper

The parseFloat method parses a valid string into the float number the string represents, leading whitespace is ignored.

Example

Lazy("12.3").parseFloat()                 // Lazy(12.3)
Lazy("-19.27").parseFloat() // Lazy(-19.27)
Lazy(["-9", "8.2", "3.923"]).parseFloat() // Lazy([-9, 8.2, 3.923])

Returns

LazyWrapper

this Lazy Object with updated value, String → Number, String[] → Number[]


trim

trim(): LazyWrapper

The trim method removes leading and trailing whitespace from the string

Example

Lazy("  abc 123  ").trim()           // Lazy("abc 123")
Lazy("Nice Job! ").trim() // Lazy("Nice Job!")
Lazy(["1.21 ", " Food?"]).trim() // Lazy(["1.21", "Food?"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


trimStart

trimStart(): LazyWrapper

The trimStart method removes only leading whitespace from the string

Example

Lazy("  abc 123  ").trim()           // Lazy("abc 123  ")
Lazy("Nice Job! ").trim() // Lazy("Nice Job! ")
Lazy(["1.21 ", " Food?"]).trim() // Lazy(["1.21 ", "Food?"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


trimEnd

trimEnd(): LazyWrapper

The trimEnd method removes only trailing whitespace from the string

Example

Lazy("  abc 123  ").trim()           // Lazy("  abc 123")
Lazy("Nice Job! ").trim() // Lazy("Nice Job!")
Lazy(["1.21 ", " Food?"]).trim() // Lazy(["1.21", " Food?"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


substring

substring(indexStart, indexEnd?): LazyWrapper

The substring method keeps only the part of the string from the start index up-to and excluding the end index. Use negative index values to index from the end of the string.

Example

Lazy("food").substring(1)               // Lazy("ood")
Lazy("food").substring(1, 3) // Lazy("oo")
Lazy("food").substring(1, -1) // Lazy("oo")
Lazy(["abc123", "123abc"]).substring(3) // Lazy(["123", "abc"])

Parameters

NameTypeDescription
indexStartnumberthe first character to be included in the string
indexEnd?numberthe first character to be excluded in the string

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


repeat

repeat(count): LazyWrapper

The repeat method take the given string an copies a specified about if times

Example

Lazy("a").repeat(5)               // Lazy("aaaaa")
Lazy("Nice").repeat(2) // Lazy("NiceNice")
Lazy(["a", "b", "c"]).repeat(3) // Lazy(["aaa", "bbb", "ccc"])

Parameters

NameTypeDescription
countnumberthe number of times the string will be repeated

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


replace

replace(pattern, replacement): LazyWrapper

The replace method search the string for a pattern and replaces every occurence of that pattern

Example

Lazy("a-a-a").replace("-", "_")         // Lazy("a_a_a")
Lazy("one2").replace(/[a-z]/g, "1") // Lazy("1112")
Lazy(["a", "d", "e"]).repeat("a", "bc") // Lazy(["ab", "c", "d"])

Parameters

NameTypeDescription
patternstring | RegExpthe search pattern
replacementstringthe string to replace all occurences of the pattern with

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


replaceOne

replaceOne(pattern, replacement): LazyWrapper

The replaceOne method search the string for a pattern and replaces the first occurence of that pattern

Example

Lazy("a-a-a").replace("-", "_")         // Lazy("a_a_a")
Lazy("one2").replace(/[a-z]/g, "1") // Lazy("1112")
Lazy(["a", "d", "e"]).repeat("a", "bc") // Lazy(["ab", "c", "d"])

Parameters

NameTypeDescription
patternstring | RegExpthe search pattern
replacementstringthe string to replace the first occurences of the pattern with

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


toUpper

toUpper(): LazyWrapper

The toUpper method coverts all characters to their upper case varient

Example

Lazy("Hello World").toUpper()   // Lazy("HELLO WORLD")
Lazy("NO way!").toUpper() // Lazy("NO WAY!")
Lazy(["A", "b", "C"]).toUpper() // Lazy(["A", "B", "C"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


toLower

toLower(): LazyWrapper

The toLower method coverts all characters to their lower case varient

Example

Lazy("Hello World").toUpper()   // Lazy("hello world")
Lazy("NO way!").toUpper() // Lazy("no way!")
Lazy(["A", "b", "C"]).toUpper() // Lazy(["a", "b", "c"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


upperCase

upperCase(): LazyWrapper

The upperCase method coverts any naming case convention to the upper case naming convention.

Example

Lazy("foo-bar").upperCase()              // Lazy("FOO BAR")
Lazy("FOO BAR").upperCase() // Lazy("FOO BAR")
Lazy("fooBar").upperCase() // Lazy("FOO BAR")
Lazy(["FOO_BAR", "foo,bar"]).upperCase() // Lazy(["FOO BAR", "FOO BAR"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


lowerCase

lowerCase(): LazyWrapper

The lowerCase method coverts any naming case convention to the lower case naming convention.

Example

Lazy("foo-bar").lowerCase()              // Lazy("foo bar")
Lazy("FOO BAR").lowerCase() // Lazy("foo bar")
Lazy("fooBar").lowerCase() // Lazy("foo bar")
Lazy(["FOO_BAR", "foo,bar"]).lowerCase() // Lazy(["foo bar", "foo BAR"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


titleCase

titleCase(): LazyWrapper

The titleCase method coverts any naming case convention to the title case naming convention.

Example

Lazy("foo-bar").titleCase()              // Lazy("Foo Bar")
Lazy("FOO BAR").titleCase() // Lazy("Foo Bar")
Lazy("fooBar").titleCase() // Lazy("Foo Bar")
Lazy(["FOO_BAR", "foo,bar"]).titleCase() // Lazy(["Foo Bar", "Foo Bar"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


snakeCase

snakeCase(): LazyWrapper

The snakeCase method coverts any naming case convention to the snake case naming convention.

Example

Lazy("foo-bar").snakeCase()              // Lazy("foo_bar")
Lazy("FOO BAR").snakeCase() // Lazy("foo_bar")
Lazy("fooBar").snakeCase() // Lazy("foo_bar")
Lazy(["FOO_BAR", "foo,bar"]).snakeCase() // Lazy(["foo_bar", "foo_bar"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


pascalCase

pascalCase(): LazyWrapper

The pascalCase method coverts any naming case convention to the pascal case naming convention.

Example

Lazy("foo-bar").pascalCase()              // Lazy("FooBar")
Lazy("FOO BAR").pascalCase() // Lazy("FooBar")
Lazy("fooBar").pascalCase() // Lazy("FooBar")
Lazy(["FOO_BAR", "foo,bar"]).pascalCase() // Lazy(["FooBar", "FooBar"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


camelCase

camelCase(): LazyWrapper

The camelCase method coverts any naming case convention to the camel case naming convention.

Example

Lazy("foo-bar").camelCase()              // Lazy("fooBar")
Lazy("FOO BAR").camelCase() // Lazy("fooBar")
Lazy("fooBar").camelCase() // Lazy("fooBar")
Lazy(["FOO_BAR", "foo,bar"]).camelCase() // Lazy(["fooBar", "fooBar"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


kebabCase

kebabCase(): LazyWrapper

The kebabCase method coverts any naming case convention to the kebab case naming convention.

Example

Lazy("foo-bar").kebabCase()              // Lazy("foo-bar")
Lazy("FOO BAR").kebabCase() // Lazy("foo-bar")
Lazy("fooBar").kebabCase() // Lazy("foo-bar")
Lazy(["FOO_BAR", "foo,bar"]).kebabCase() // Lazy(["foo-bar", "foo-bar"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


encodeBase64

encodeBase64(): LazyWrapper

The encodeBase64 method encodes any string into a base64 format string

Example

Lazy("helloworld324234").encodeBase64() // Lazy("aGVsbG93b3JsZDMyNDIzNA==")
Lazy(["123", "$1@#"]).encodeBase64() // Lazy(["MTIz", "JDFAIw=="])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


decodeBase64

decodeBase64(): LazyWrapper

The decodeBase64 method decodes any base64 format string into a regular string

Example

Lazy("aGVsbG93b3JsZDMyNDIzNA==").decodeBase64() // Lazy("helloworld324234")
Lazy(["MTIz", "JDFAIw=="]).decodeBase64() // Lazy(["123", "$1@#"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


encodeURL

encodeURL(): LazyWrapper

The encodeURL method encodes a URI by replacing unsported characters with UTF-8 supported escape character

Example

Lazy("werewr@#$#@").encodeURL()    // Lazy("erewr%40%23%24%23%40")
Lazy(["1=1", "AbC+"]).encodeURL() // Lazy(["AbC%2B", "1%3D1"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


decodeURL

decodeURL(): LazyWrapper

The decodeURL method decodes a URI by converting UTF-8 escape characters back to their orginal character, created by .encodeURL()

Example

Lazy("erewr%40%23%24%23%40").encodeURL() // Lazy("werewr@#$#@")
Lazy(["AbC%2B", "1%3D1"]).encodeURL() // Lazy(["1=1", "AbC+"])

Returns

LazyWrapper

this Lazy Object with updated value, String → String, String[] → String[]


split

split(separator, limit?): LazyWrapper

The split method splits a string at any occurence of the pattern into an array

Example

Lazy("a-b-c-d-e-f").split("-")      // Lazy(["a", "b", "c", "d", "e", "f"])
Lazy("a-b-c-d-e-f").split("-", 3) // Lazy(["a", "b", "c"])
Lazy("a-b/c-d").split((/[\-/]/, 3) // Lazy(["a", "b", "c"])
Lazy(["a-b", "b-c", "c-d"]).split() // Lazy([["a", "b"], ["b", "c"], ["c", "d"]])

Parameters

NameTypeDescription
separatorstring | RegExp-
limit?numberthe max number of subarrays to be included in the result

Returns

LazyWrapper

this Lazy Object with updated value, String → String[], String[] → String[][]