- (feat) add concept of post processors
- (feat) add 'key as default value' post processor (closes #109) - (chore) move clean functionality to a post processor - (chore) move sort functionality to a post processor - (refactor) get rid of leading underscore on protected properties/methods
This commit is contained in:
12
src/post-processors/key-as-default-value.post-processor.ts
Normal file
12
src/post-processors/key-as-default-value.post-processor.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TranslationCollection } from '../utils/translation.collection';
|
||||
import { PostProcessorInterface } from './post-processor.interface';
|
||||
|
||||
export class KeyAsDefaultValuePostProcessor implements PostProcessorInterface {
|
||||
|
||||
public name: string = 'KeyAsDefaultValue';
|
||||
|
||||
public process(working: TranslationCollection, extracted: TranslationCollection, existing: TranslationCollection): TranslationCollection {
|
||||
return working.map((key, val) => val === '' ? key : val);
|
||||
}
|
||||
|
||||
}
|
||||
9
src/post-processors/post-processor.interface.ts
Normal file
9
src/post-processors/post-processor.interface.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { TranslationCollection } from '../utils/translation.collection';
|
||||
|
||||
export interface PostProcessorInterface {
|
||||
|
||||
name: string;
|
||||
|
||||
process(working: TranslationCollection, extracted: TranslationCollection, existing: TranslationCollection): TranslationCollection;
|
||||
|
||||
}
|
||||
12
src/post-processors/purge-obsolete-keys.post-processor.ts
Normal file
12
src/post-processors/purge-obsolete-keys.post-processor.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TranslationCollection } from '../utils/translation.collection';
|
||||
import { PostProcessorInterface } from './post-processor.interface';
|
||||
|
||||
export class PurgeObsoleteKeysPostProcessor implements PostProcessorInterface {
|
||||
|
||||
public name: string = 'PurgeObsoleteKeys';
|
||||
|
||||
public process(working: TranslationCollection, extracted: TranslationCollection, existing: TranslationCollection): TranslationCollection {
|
||||
return working.intersect(extracted);
|
||||
}
|
||||
|
||||
}
|
||||
12
src/post-processors/sort-by-key.post-processor.ts
Normal file
12
src/post-processors/sort-by-key.post-processor.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TranslationCollection } from '../utils/translation.collection';
|
||||
import { PostProcessorInterface } from './post-processor.interface';
|
||||
|
||||
export class SortByKeyPostProcessor implements PostProcessorInterface {
|
||||
|
||||
public name: string = 'SortByKey';
|
||||
|
||||
public process(working: TranslationCollection, extracted: TranslationCollection, existing: TranslationCollection): TranslationCollection {
|
||||
return working.sort();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user