diff --git a/src/utils/common/ecosystem.ts b/src/utils/common/ecosystem.ts index a07ad81..e69de29 100644 --- a/src/utils/common/ecosystem.ts +++ b/src/utils/common/ecosystem.ts @@ -1,36 +0,0 @@ -type Configuration = Record; -type Builder = (config: T) => () => any; - -export class Registry { - private registry: Map = new Map(); - - register(key: K, builder: Builder): void { - if (this.registry.has(key)) { - throw new Error(`Builder with key '${key}' is already registered`); - } - this.registry.set(key, builder); - } - - has(key: K): boolean { - return this.registry.has(key); - } - - get(key: K): Builder { - if (!this.has(key)) { - throw new Error(`There is no builder with key '${key}' registered`); - } - - return this.registry.get(key)!; - } - - remove(key: K): boolean { - if (!this.registry.has(key)) { - throw new Error(`Builder with key '${key}' does not exist`); - } - return this.registry.delete(key); - } - - allNames(): K[] { - return Array.from(this.registry.keys()); - } -} diff --git a/src/utils/common/index.ts b/src/utils/common/index.ts index dd04ef2..c3adad9 100644 --- a/src/utils/common/index.ts +++ b/src/utils/common/index.ts @@ -4,4 +4,4 @@ export * from './charsets'; export * from './casing'; export * from './objectManipulation'; export * from './sorting'; -export * from './ecosystem'; +export * from './registry'; diff --git a/src/utils/common/registry.ts b/src/utils/common/registry.ts new file mode 100644 index 0000000..a07ad81 --- /dev/null +++ b/src/utils/common/registry.ts @@ -0,0 +1,36 @@ +type Configuration = Record; +type Builder = (config: T) => () => any; + +export class Registry { + private registry: Map = new Map(); + + register(key: K, builder: Builder): void { + if (this.registry.has(key)) { + throw new Error(`Builder with key '${key}' is already registered`); + } + this.registry.set(key, builder); + } + + has(key: K): boolean { + return this.registry.has(key); + } + + get(key: K): Builder { + if (!this.has(key)) { + throw new Error(`There is no builder with key '${key}' registered`); + } + + return this.registry.get(key)!; + } + + remove(key: K): boolean { + if (!this.registry.has(key)) { + throw new Error(`Builder with key '${key}' does not exist`); + } + return this.registry.delete(key); + } + + allNames(): K[] { + return Array.from(this.registry.keys()); + } +}