Assert a condition and throw an Error if the condition isn't met.
Usage:
assert()assert(cond)cond. If it is false, throws an
Error.assert(cond, msg)cond. If it is false, throws an
Error, whose description property
is set to msg.assert(cond, msg, objs...)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.| Name | Type | Argument | Description |
|---|---|---|---|
condition |
boolean | ||
message |
string |
<optional> |
the message |
values |
object |
<optional> <repeatable> |
an optional list of values |
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")
Asserts that val is a number.
val is a number.
| 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 |
Asserts that val is defined and non-null.
val is defined and non-null.
| 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 |
import {assertSomething} from 'josm/util'
assertSomething(null) // -> throws an exception
assertSomething(void 0) // -> throws an exception
assertSomting("test") // -> OK
assertSomething(5) // -> OK
Replies the number of properties owned by o.
o.
| Name | Type | Description |
|---|---|---|
o |
any | the object |
o.
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
Iteraties over the elements of a collection
collection and invokes
delegate() on each element.
| Name | Type | Description |
|---|---|---|
collection |
array | arguments | Collection | the collection of elements |
delegate |
function | the function to call on each elemennt |
Replies true, if o owns at least one property.
o owns at least one property.
| Name | Type | Description |
|---|---|---|
o |
any | the object |
o owns at least one property.
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
Replies true if val is a list of arguments.
val is a list of arguments.
| Name | Type | Description |
|---|---|---|
value |
anything | the value to check |
Replies true if val is an array.
val is an array.
| Name | Type | Description |
|---|---|---|
value |
anything | the value to check |
Is a value a collection?
| Name | Type | Description |
|---|---|---|
value |
object | the value to check |
value is a collection
Returns true if val is defined.
val is defined.
| Name | Type | Description |
|---|---|---|
value |
any | the value to check |
val is defined
Replies true, if f is a function.
| Name | Type | Description |
|---|---|---|
f |
any | the object |
Returns true if val is a number.
val is a number.
| Name | Type | Description |
|---|---|---|
value |
any | the value to check |
val is a number
Returns true if val is a string.
val is a string.
| Name | Type | Description |
|---|---|---|
value |
any | the value to check |
Are two java objects equal.
| Name | Type | Description |
|---|---|---|
o1 |
object | a java object or null |
o2 |
object | a java object or null |
Mixes the properties of a list of objects into one object.
Prints a message to stdout (without newline).
| Name | Type | Argument | Description |
|---|---|---|---|
message |
string | ||
args |
object |
<optional> <repeatable> |
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 '{'}")
Prints a message to stdout (including newline).
| Name | Type | Argument | Description |
|---|---|---|---|
message |
string | ||
args |
object |
<optional> <repeatable> |
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 '{'}");
Checks whether a value is null or undefined.
| Name | Type | Description |
|---|---|---|
value |
object | the value to check |
value is null or undefined; true, otherwise
Checks whether a value is neither null nor undefined.
| Name | Type | Description |
|---|---|---|
value |
object | the value to check |
value is null or undefined; true, otherwise
Trims leading and trailing whitespace from s.
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.
| Name | Type | Description |
|---|---|---|
s |
string | the string to be trimmed |