Members
-
clone
-
Create a new object as a shallow copy of the passed in value.
Example
source = { a: 1, b: invalid, c: "3" } dest = _.clone(source)
-
cloneDeep
-
Create a new object as a deep copy of the passed in value.
Example
source = [{ a: 1, b: invalid, c: "3" }] dest = _.clone(source)
-
cond
-
Conditionally return something based on boolean argument.
Native equivalent:
if true x = 1 else x = 2 end if
Example
x = _.cond(true, 1, 2)
-
createRequest
-
Create a new request object - inspired by node-fetch
Example
' Simple request r = _.createRequest("http://www.google.com") response = r.start(true) ' Complex request with options headers = { "Content-type": "application/json" } r = _.createRequest("http://www.google.com", { method: "GET", headers: headers }) port = CreateObject("roMessagePort") r.start(false, port) message = wait(3000, port) result = r.handleEvent(message)
-
deleteAll
-
Delete all registry entries for the channel
Example
_.regDeleteAll()
-
difference
-
Return a new array of items from the first which are not in the second.
Example
difference = _.difference([1,2], [2]) ' => [1]
-
empty
-
Test for a string, array, or object to be invalid, length, or count of zero.
Example
_.empty(invalid)) ' => true _.empty("")) ' => true _.empty("abc")) ' => false _.empty({})) ' => true _.empty({a:1})) ' => false _.empty([])) ' => true
-
equal
-
Enhance the native '=' operator by catching type mismatch errors.
Example
_.equal(invalid, "a") ' => false
-
get
-
Resolve a nested 'dot' notation path safely. This is primarily allow things like "myValue = a.b.c.d.e.f" to run without crashing the VM when an intermediate value is invalid.
Example
data = { a: 1 b: { c: 2 d: { e: 3 f: [4, 5] } } } value = _.get(data, ["b","d","f"]) ' => [4, 5] value = _.get(data, "b.d.f[0]") ' => 4 value = _.get(data, "a[0]") ' => invalid
-
getDeviceProfile
-
Get most static information about the device from ifDeviceInfo and ifAppInfo. The values included here shouldn't change through the duration of the channel running and can be cached.
Example
_.getDeviceProfile() ' => { "deviceInfo": { "model": "4200X", ... } }
-
getManifest
-
Read and parse the manifest file manually in order to retrieve all key/value pairs. Manifest is always at pkg:/manifest, but can be overridden for testing
Example
_.getManifest() ' => { "title": "My Channel", ... }
-
indexOf
-
Find the integer index of an item within an array. Uses _.equal to test for same item.
Example
_.indexOf(["a","b","c"], c) ' => 2
-
intersection
-
Return a new array of items from the first which are also in the second.
Example
intersection = _.intersection([1,2], [2]) ' => [2]
-
map
-
Execute a function over all items of an object, collecting the results into an array.
Example
_.map([1,2,3], Function(x): return x*x: End Function) ' => [1,4,9]
-
max
-
Return the maximum of 2 numeric arguments, or invalid if one or both of them is non-numeric
Example
_.max(2,1) ' => 2
-
min
-
Return the minimum of 2 numeric arguments, or invalid if one or both of them is non-numeric
Example
_.min(2,1) ' => 1
-
regDelete
-
Delete the registry key from sectionName
Example
_.regDelete("session", "cookie")
-
regRead
-
Read registry at key in sectionName and deserialize from JSON string.
Example
_.regRead("auth", "password") ' => "secret123abc!" _.regRead("user", "bookmarkIds") ' => [1,2,3] _.regRead("user", "settings") ' => {a:1, b:2}
-
regReadAll
-
Read the entire registry for the channel.
Example
_.regReadAll() ' => { "section1": { "key1": "value1", "key2: "value2"}, "section2": ... }
-
regWrite
-
Serialize value to JSON string and write to the registry at key in sectionName.
Example
_.regWrite("auth", "password", "secret123abc!") _.regWrite("user", "bookmarkIds", [1,2,3]) _.regWrite("user", "settings", {a:1, b:2})
-
regWriteAll
-
Write the entire registry for the channel. By default this overwrites any existing data, but will not remove any sections or keys
Example
_.regWriteAll({ "section1": { "key1": "value1", "key2: "value2"}, "section2": ... })
-
set
-
Use nested 'dot' notation path to set a value within an object. This function will create intermediate objects as necessary.
Example
data = _.set({}, ["b","d","f"], 3) ' => {b: { d: { f: 3}}}
-
uriEncodeParams
-
Encode an associative array to a urlencoded query string or post body
Example
_.uriEncodeParams({ a: 1, b: 2, c: "three", d: "four with spaces"}) ' => "a=1&b=2&c=three&d=four%20with%20spaces"
-
uriParse
-
Parse a string uri into its parts.
Example
_.uriParse("https://www.google.com/#q=bees") ' => { scheme: "https", host: "www.google.com", hash: ... }