Module: josm/util

Provides a set of static utility functions.
Source:

Methods


<static> assert(condition [, message] [, values])

Assert a condition and throw an Error if the condition isn't met.

Assert a condition and throw an Error if the condition isn't met.

Usage:

assert()
Does nothing
assert(cond)
Checks the condition cond. If it is false, throws an Error.
assert(cond, msg)
Checks the condition cond. If it is false, throws an Error, whose description property is set to msg.
assert(cond, msg, objs...)
Checks the condition cond. If it is false, throws an Error, whose description property is set to the formatted message msg. Internally uses java.text.MessageFormat to format the message.
Parameters:
Name Type Argument Description
condition boolean
message string <optional>
the message
values object <optional>
<repeatable>
an optional list of values
Source:
Example
import {assert} from 'josm/util'
// throws an Error
assert(false)

// throws an Error e, with e.description == "My message"
assert(false, "My message")

// throws an Error e, with e.description == "My message: test"
assert(false, "My message: {0}", "test")

<static> assertNumber(value [, msg] [, values])

Asserts that val is a number.

Asserts that val is a number.
Parameters:
Name Type Argument Description
value Anything the value to check
msg String <optional>
message if the assertion fails
values object <optional>
<repeatable>
values used in msg placeholders
Source:

<static> assertSomething(val [, msg] [, values])

Asserts that val is defined and non-null.

Asserts that val is defined and non-null.
Parameters:
Name Type Argument Description
val any the value to check
msg string <optional>
message if the assertion fails
values object <optional>
<repeatable>
additional values used in msg placeholders
Source:
Example
import {assertSomething} from 'josm/util'

assertSomething(null)     // -> throws an exception
assertSomething(void 0)   // -> throws an exception

assertSomting("test")     // -> OK
assertSomething(5)        // -> OK

<static> countProperties(o)

Replies the number of properties owned by o.

Replies the number of properties owned by o.
Parameters:
Name Type Description
o any the object
Source:
Returns:
the number of properties owned by o.
Type
number
Example
import {countProperties} from 'josm/util'

let o = {p1: "v1", p2: "v2"}
let c = countProperties(o)   // ->  2

o = {}
c = countProperties(o)       // ->  0

o = undefined
c = countProperties(o)       // ->  undefined

<static> each(collection, delegate)

Iteraties over the elements of a collection

Iterates over the elements in collection and invokes delegate() on each element.
Parameters:
Name Type Description
collection array | arguments | Collection the collection of elements
delegate function the function to call on each elemennt
Source:

<static> hasProperties(o)

Replies true, if o owns at least one property.

Replies true, if o owns at least one property.
Parameters:
Name Type Description
o any the object
Source:
Returns:
true, if o owns at least one property.
Type
boolean
Example
import {hasProperties} from 'josm/util'

let o = {p1: "v1", p2: "v2"}
let c = hasProperties(o)         // ->  true

o = {}
c = hasProperties(o)             // ->  false

o = undefined
c = hasProperties(o)             // ->  false

<static> isArguments(value)

Replies true if val is a list of arguments.

Replies true if val is a list of arguments.
Parameters:
Name Type Description
value anything the value to check
Source:
Returns:
true, if val is a list of arguments
Type
boolean

<static> isArray(value)

Replies true if val is an array.

Replies true if val is an array.
Parameters:
Name Type Description
value anything the value to check
Source:
Returns:
true, if val is an array
Type
boolean

<static> isCollection(value)

Is a value a collection?

Replies true, if a value is an array, an arguments list or a Java collection.
Parameters:
Name Type Description
value object the value to check
Source:
Returns:
true, if value is a collection
Type
boolean

<static> isDef(value)

Returns true if val is defined.

Returns true if val is defined.
Parameters:
Name Type Description
value any the value to check
Source:
Returns:
true if val is defined
Type
boolean

<static> isFunction(f)

Replies true, if f is a function.

Replies true, if f is a function.
Parameters:
Name Type Description
f any the object
Source:
Returns:
true, if f is a function.
Type
boolean

<static> isNumber(value)

Returns true if val is a number.

Returns true if val is a number.
Parameters:
Name Type Description
value any the value to check
Source:
Returns:
true if val is a number
Type
boolean

<static> isString(value)

Returns true if val is a string.

Returns true if val is a string.
Parameters:
Name Type Description
value any the value to check
Source:
Returns:
true, if val is a string or a String object
Type
boolean

<static> javaEquals(o1, o2)

Are two java objects equal.

Checks whether two java objects are either both null or equal by calling o1.equals(o2).
Parameters:
Name Type Description
o1 object a java object or null
o2 object a java object or null
Source:
Returns:
Type
boolean

<static> mix()

Mixes the properties of a list of objects into one object.

Mixes the properties of a list of objects into one object.
Source:
Returns:
  • a new object which includes the combined properties of the argument objects
  • Type
    object

<static> print(message [, args])

Prints a message to stdout (without newline).

Prints a message to stdout (without newline). Supports the same string templates as MessageFormat
Parameters:
Name Type Argument Description
message string
args object <optional>
<repeatable>
Source:
Example
import * as util from 'josm/util'

const  myname = "..."
util.print('Hello world! My name is {0}', myname)
// escape meta characters like {, } or ' with a leading apostrophe
util.print(" a pair of curly braces '{'}")

<static> println(message [, args])

Prints a message to stdout (including newline).

Prints a message to stdout (including newline). Supports the same string templates as MessageFormat.
Parameters:
Name Type Argument Description
message string
args object <optional>
<repeatable>
Source:
Example
import * as util from 'josm/util'

const myname = '...'
util.println('Hello world! My name is {0}', myname);
// escape meta characters like {, } or ' with a leading apostrophe
util.println(" a pair of curly braces '{'}");

<inner> isNothing(value)

Checks whether a value is null or undefined.

Checks whether a value is null or undefined.
Parameters:
Name Type Description
value object the value to check
Source:
Returns:
false, if value is null or undefined; true, otherwise
Type
boolean

<inner> isSomething(value)

Checks whether a value is neither null nor undefined.

Checks whether a value is neither null nor undefined.
Parameters:
Name Type Description
value object the value to check
Source:
Returns:
false, if value is null or undefined; true, otherwise
Type
boolean

<inner> trim(s)

Trims leading and trailing whitespace from s.

Trims leading and trailing whitespace from s.

Replies s, if s is null or undefined. Any other value is converted to a string, then leading and trailing white space is removed.

Parameters:
Name Type Description
s string the string to be trimmed
Source:
Returns:
Type
string