diff --git a/lib/builders/dictionaries/dictionaryBuilder.ts b/lib/builders/dictionaries/dictionaryBuilder.ts new file mode 100644 index 0000000..def5236 --- /dev/null +++ b/lib/builders/dictionaries/dictionaryBuilder.ts @@ -0,0 +1,37 @@ +import {DictionaryTranslationBuilder} from "./dictionaryTranslationBuilder"; + +export class DictionaryBuilder { + name: string; + parentId: string; + dictionaryTranslationBuilder; + + constructor() { + this.dictionaryTranslationBuilder = []; + } + + withName(name: string) { + this.name = name; + return this; + } + + addTranslation() { + const builder = new DictionaryTranslationBuilder(this); + this.dictionaryTranslationBuilder.push(builder); + return builder; + } + + withParentId(parentId: string) { + this.parentId = parentId; + return this; + } + + build() { + return { + name: this.name || undefined, + translations: this.dictionaryTranslationBuilder.map(builder => { + return builder.build(); + }), + parentId: this.parentId || undefined + } + } +} \ No newline at end of file diff --git a/lib/builders/dictionaries/dictionaryTranslationBuilder.ts b/lib/builders/dictionaries/dictionaryTranslationBuilder.ts new file mode 100644 index 0000000..850f1be --- /dev/null +++ b/lib/builders/dictionaries/dictionaryTranslationBuilder.ts @@ -0,0 +1,32 @@ +import {DictionaryBuilder} from "./dictionaryBuilder"; + +export class DictionaryTranslationBuilder { + isoCode: string; + translation: string; + parentBuilder: DictionaryBuilder; + + constructor(parentBuilder: DictionaryBuilder) { + this.parentBuilder = parentBuilder + } + + withIsoCode(isoCode: string) { + this.isoCode = isoCode; + return this; + } + + withTranslation(translation: string) { + this.translation = translation; + return this; + } + + done() { + return this.parentBuilder; + } + + build() { + return { + isoCode: this.isoCode || "", + translation: this.translation || "" + } + } +} \ No newline at end of file diff --git a/lib/builders/dictionaries/index.ts b/lib/builders/dictionaries/index.ts new file mode 100644 index 0000000..caf59e6 --- /dev/null +++ b/lib/builders/dictionaries/index.ts @@ -0,0 +1,2 @@ +export {DictionaryBuilder} from './dictionaryBuilder'; +export {DictionaryTranslationBuilder} from './dictionaryTranslationBuilder'; \ No newline at end of file diff --git a/lib/builders/index.ts b/lib/builders/index.ts index 5d2c689..a0a1930 100644 --- a/lib/builders/index.ts +++ b/lib/builders/index.ts @@ -1,2 +1,3 @@ export * from './packages'; -export * from './dataTypes'; \ No newline at end of file +export * from './dataTypes'; +export * from './dictionaries';