Create a new ID.
These are all equivalent (mostly):
new ID("stone")
new ID("minecraft:stone")
new ID("stone", "minecraft")
The path of the ID. If namespace
is not passed this will be parsed (see ID.parseString
).
The namespace of the ID
. If this is included, path
will be used as-is.
The namespace of this ID, such as minecraft
in minecraft:stone
. If undefined, e.g. when parsed from stone
,
it will be treated as if it was specified as "minecraft" (ID.DEFAULT_NAMESPACE
)
in most cases.
Test if this is the same ID as other
. This treats a missing namespace as if
it was minecraft
.
import { ID } from "minecraft-id";
import * as assert from "assert";
assert.ok(new ID("stone").equals(new ID("minecraft:stone")));
assert.ok(!(new ID("dirt").equals(new ID("minecraft:stone"))));
assert.ok(!(new ID("minecraft:stone").equals(new ID("namespace:stone"))));
Test if this has the DEFAULT_NAMESPACE
. If the namespace is unspecified, this returns true
Test if this has the same namespace as other
.
This ignores a missing namespace
import { ID } from "minecraft-id";
import * as assert from "assert";
assert.ok(new ID("stone").sameNamespace(new ID("minecraft:stone")));
assert.ok(new ID("dirt").sameNamespace(new ID("minecraft:stone")));
assert.ok(!(new ID("minecraft:stone").sameNamespace(new ID("namespace:stone"))));
assert.ok(new ID("namespace:stone").sameNamespace(new ID("namespace:dirt")));
Convert this ID into a string. This also allows IDs to be used in certain places where strings are expected, most notably in template literals.
import * as assert from "assert";
import {ID} from "minecraft-id";
assert.strictEqual(`This is an ID - ${new ID("stone")}`, "This is an ID - minecraft:stone");
Convert a string into an ID
, with an optional seperator parameter.
This has the same behaviour as the constructor called with a single
argument if the seperator is not defined.
If the seperator is defined, it is used to overwrite the seperator
between the namespace and the tag, instead of using the default :
.
ID.fromString("stone")
is equivalent to new ID("stone")
.ID.fromString("minecraft:stone")
is equivalent to new ID("minecraft:stone")
and new ID("stone", "minecraft")
ID.fromString("minecraft.stone", ".")
is equivalent to new ID("stone", "minecraft")
This does not validate the input, and instead naïvely splits
based on the first occurance of sep
. If validation is required is
should be implemented manually, using ID.SEGMENT_REGEX
to ensure
that the segments (path and namespace) are valid
The seperator to use (defaults to :
)
Generated using TypeDoc
An ID from Minecraft, which will have a path and may have a namespace.