@tendrock/lib
Version:
A lib under the Tendrock system for Minecraft Bedrock Script API
40 lines (39 loc) • 1.25 kB
JavaScript
export class IdUtils {
static getNamespace(identifier) {
if (!identifier.includes(':')) {
return undefined;
}
return identifier.split(':')[0];
}
static getPath(identifier) {
if (!identifier.includes(':')) {
return identifier;
}
return identifier.split(':')[1];
}
static isValidId(identifier) {
return /^[a-z0-9_]+:[a-z0-9_\/]+$/.test(identifier);
}
static isVanillaId(identifier) {
return this.isValidId(identifier) && identifier.startsWith('minecraft:');
}
static getVanillaId(path) {
return `minecraft:${path}`;
}
static matchNamespace(identifier, namespace) {
return this.getNamespace(identifier) === namespace;
}
static hasNamespace(identifier) {
return identifier.includes(':');
}
static isGameObjectType(type) {
return typeof type === 'object' && type.id && typeof type.id === 'string';
}
static getTypeId(gameObjectOrType) {
if (typeof gameObjectOrType === 'string')
return gameObjectOrType;
if (this.isGameObjectType(gameObjectOrType))
return gameObjectOrType.id;
return gameObjectOrType.typeId;
}
}