Ordering, equality, and hashing
HashCode interfaces that can
be implemented by ordered, equatable, and hashable classes, respectively.
Objects object supports generic comparison, equality testing,
Objects.compare(x: unknown, y: unknown): 0 | 1 | -1 returns the relative
sort order of two comparable values. If
Objects.compare delegates to
compareTo method. If
both numbers, or both strings, they are compared lexicographically. If
y are both arrays, then each corresponding element is compared, in turn,
y are both objects, then each entry is
compared first by key, then by value, using
Objects.compare. Values of
incompatible types sort in a deterministic order based on type.
Objects.equal(x: unknown, y: unknown): boolean returns
true if two values
are equivalent. If
Objects.equal delegates to
equals method. If
y are both primitives, then they are
compared by value. If
y are both arrays, then each corresponding
element is tested for equality, in turn, using
are both objects, then each entry is tested for equality furst by key, then by
Objects.hash(x: unknown): number returns a consistent hash code for
Objects.hash delegate's to
hashCode method. If
x is a primitive, it is hashed using the
hashing algorithm. If
x is an array, each element is hashed individually
Objects.hash, and the hash codes of all elements get mixed together.
x is an object, each entry has its key and value hashed using
Objects.hash, and the hash codes of all entries get mixed together.
Murmur3 object implements the 32-bit
MurmurHash algorithm, version 3.
@swim/util provides two generic interfaces for converting between loosely
FromAny is implicitly implemented by classes that have a static
FromAny is implemented by many @swim/ui and
@swim/ux classes, and is used to abstract over the conversion of loosely
typed values to strongly typed values. For example, @swim/view's
MemberAnimator classes leverage
FromAny to generically convert loosely
typed animator arguments to strongly typed, tweenable values.
ToAny is implemented by classes that have a
tonAny method that returns a
ToAny is used to abstract over the
conversion of strongly typed values to loosely typed values.
@swim/util exports an ES6-compatible
Iterator interface, as well as a
Cursor base class for positioned iterators.
Builder interface abstracts over construction of collections.
PairBuilder interface abstracts over construction of key-value maps,
and other pair-containing collections.
@swim/util defines three key-value map interfaces: an ES6-compatible
interface, as well as an
OrderedMap interface, and a
OrderedMap has its entries sorted by key order. A
ReducedMap is an
OrderedMap that memoizes partial combinations of sub-elements to support
efficient, incremental reduction of continuously mutating datasets.
HashGenCacheSet implement efficient hashed generational
caches that discard the least recently used value with the worst hit rate per
Assert interface provides a common API for constraint testing
and contract enforcement. The exported
assert singleton provides a default
Assert implementation that throws
AssertException on assert failure.
For an npm-managed project,
npm install @swim/util to make it a dependency.
TypeScript sources will be installed into
node_modules/@swim/util/lib/main. And a pre-built UMD script can
be found in
Browser applications can load
swim-core.js, which comes bundled with the
@swim/util library, directly from the swimOS CDN.
<!-- Development --><!-- Production -->
Alternatively, the standalone
swim-system.js script may be loaded
from the swimOS CDN, which bundles @swim/util together with all other
<!-- Development --><!-- Production -->
@swim/util can be imported as an ES6 module from TypeScript and other ES6-compatible environments.
@swim/util can also be used as a CommonJS module in Node.js applications.
var util = ;
When loaded by a web browser, the
swim-core.js script adds all
@swim/util library exports to the global
swim-system.js script also adds all @swim/util library exports
to the global
swim namespace, making it a drop-in replacement for
swim-core.js when additional @swim/system libraries are needed.