Lodash - utility

API

.diffMilliseconds()

.diffMilliseconds(start : Integer; end : Integer) : Integer

Returns the difference between two millisecond values, accounting for possible negative overflow.


.exec()

.exec(command : text { ; wait : Real }) : Text

This is a convenience function that makes it easier to use 4D.SystemWorkeropen in new window. The function executes command, waiting wait seconds for the process to complete. If wait is omitted or zero, it defaults to 1.

If the command executes successfully (.exitCodeopen in new window=0), the outputopen in new window of the command is trimmed of leading and trailing line breaks and returned.

If command is not a valid command, terminates unexpectedly, or returns a non-zero .exitCode, .responseErroropen in new window is trimmed of leading and trailing line breaks and thrown as a SystemError, and an empty string is returned.


.getClassesInFolder()

.getClassesInFolder(folder : Text { ; fullPaths : Boolean }) : Collection

Returns a collection of all classes in the Home folder named folder. If fullPaths is false (the default), only class names are returned. If fullPaths is true, full paths to the classes (e.g. [class]/MyClass) are returned.


.popCharacterSet()

.popCharacterSet() : Object

js.component maintains a stack of input/output character sets. Unlike USE CHARACTER SETopen in new window, you can easily push and pop character sets, and in addition set both the input and output character set in one operation. At startup the character set stack is set to utf-8 for both input and output.

If there is more than one character set on the character set stack, this function:

  • Pops the character set stack.
  • Sets the current character set to the new top of the stack.
  • Returns the previous character set info as an object with "charSet" and "inOut" properties.

Otherwise the current character set remains unchanged and null is returned.


.printStackTrace()

.printStackTrace(stack : Collection { ; indent : Integer }) : Text

Returns a formatted stack trace from stack, which should be in the format returned by Get call chain. If indent is omitted or <= 0, it defaults to 4 (spaces).

Each frame of the stack is in the following format:

at <db>.<class>.<function>:<line>

NOTE

<line> is the line number within <function>, not the line number within the source file.

For example, when _.parseJSON encounters malformed JSON, it throws an error with a stack trace that looks like this:

at js.component._LodashString.parseJSON:12
at js.component.Lodash.parseJSON:1
at mydb.parseFile:20

.pushCharacterSet()

.pushCharacterSet(charSet : Text { ; inOut : Text | Integer }) : Boolean

js.component maintains a stack of input/output character sets. Unlike USE CHARACTER SETopen in new window, you can easily push and pop character sets, and in addition set both the input and output character set in one operation. At startup the character set stack is set to utf-8 for both input and output.

This function pushes the given character set on the character sets stack and sets it to be the current character set (via USE CHARACTER SET) for input and/or output.

inOut determines which direction the character set applies to. inOut may have the following values:

0 | "out" | "write"
1 | "in"  | "read"
2 | "*"   | "rw" | "read/write"

If charSet is a valid IANA character set name:

  • The object { "charSet": $charSet, "inOut": $inOut } is pushed on the character set stack.
  • true is returned.

If charSet is not a valid IANA character set name:

  • _.lastError will contain an error.

  • The object { "charSet": "utf-8", "inOut": 0 } is pushed on the character set stack.

  • false is returned.


.randomBetween()

.randomBetween(start : Integer; end : Integer { ; exclusive : Boolean }) : Integer

Returns a random integer between start and end. If exclusive is not passed or is false, the result is inclusive of start and end, otherwise it is exclusive of end (e.g. end - 1).

Passing true for exclusive is useful when dealing with zero-based collection indexes, where start is zero and end is the length of the collection.


.valueForKeyPath()

.valueForKeyPath(value : Object | Collection; keyPath : Text) : any

Returns the value specified by keyPath, which should be a dotted path to a key starting from the top level of value.

Each segment of the path may either be a key or an index. If a segment is an index, it must be enclosed in square brackets. For example, foo.[0].bar is a valid key path, but foo.0.bar is not.

If value is null, or if the key path is not valid, undefined is returned.

Key segments

If a segment of the path is a key, the value of the previous segment may be an object, a collection, or a string.

NOTE

Keys may consist of word characters, hyphens, underscores and "$".

If the value is an object or a collection, the following property lookup is performed in this order:

value.<key>
value.get<Key>
value.is<Key>
value._<key>

If the property exists and is a function, it is invoked with no arguments and This set to the value. The result of the function is used as the value of the segment. If the property exists and is not a function, it is used as the value of the segment. Otherwise undefined is returned.

If the value of the previous segment is a string and the key is length, the length of the string is returned.

Index segments

If a segment of the path is an index, the value of the previous segment may be a collection or a string.

If the value is a collection, the index is converted to an integer and the element at that zero-based index is returned.

If the value is a string, the index is converted to an integer and the character at that one-based index is returned.

In either case, if the index is negative it is relative to the end of the value. If the index is out of range, undefined is returned.

Examples

$object:=_.json("{ 'boo': { 'baz': [7, { 'qux': 'cool' }], 'bool': true, 'third': { 'level': 7 } }}")

$value:=_.valueForKeyPath($object; "boo.third.level")
// $value => 7

$value:=_.valueForKeyPath($object; "boo.baz[1].qux")
// $value => "cool"

$value:=_.valueForKeyPath($object; "boo.baz[1].qux.[-1]")
// $value => "l"

$folder:=Folder("/usr/local")
$object:=New object("folder"; $folder)
$value:=_.valueForKeyPath($object; "folder.folders.[0].path")
// $value => "/usr/local/bin"

$object:=_.json("{ 'foo': [1, 2, 3] }")
$value:=_.valueForKeyPath($object; "foo.sum")
// $value => 6

.version

.version : Text

Contains the current version of js.component. This property is read-only.

Last Updated:
Contributors: Aparajita