fix: strip bom from json files. Closes #94
This commit is contained in:
parent
bc2bfac7d7
commit
7d1bcd2a80
@ -1,7 +1,8 @@
|
||||
import { CompilerInterface } from './compiler.interface';
|
||||
import { TranslationCollection } from '../utils/translation.collection';
|
||||
import { stripBOM } from '../utils/utils';
|
||||
|
||||
import * as flat from 'flat';
|
||||
import { flatten } from 'flat';
|
||||
|
||||
export class JsonCompiler implements CompilerInterface {
|
||||
|
||||
@ -20,9 +21,9 @@ export class JsonCompiler implements CompilerInterface {
|
||||
}
|
||||
|
||||
public parse(contents: string): TranslationCollection {
|
||||
let values: any = JSON.parse(contents);
|
||||
let values: any = JSON.parse(stripBOM(contents));
|
||||
if (this.isNamespacedJsonFormat(values)) {
|
||||
values = flat.flatten(values);
|
||||
values = flatten(values);
|
||||
}
|
||||
return new TranslationCollection(values);
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { CompilerInterface } from './compiler.interface';
|
||||
import { TranslationCollection } from '../utils/translation.collection';
|
||||
import { stripBOM } from '../utils/utils';
|
||||
|
||||
import * as flat from 'flat';
|
||||
import { flatten, unflatten } from 'flat';
|
||||
|
||||
export class NamespacedJsonCompiler implements CompilerInterface {
|
||||
|
||||
@ -16,14 +17,14 @@ export class NamespacedJsonCompiler implements CompilerInterface {
|
||||
}
|
||||
|
||||
public compile(collection: TranslationCollection): string {
|
||||
const values: {} = flat.unflatten(collection.values, {
|
||||
const values: {} = unflatten(collection.values, {
|
||||
object: true
|
||||
});
|
||||
return JSON.stringify(values, null, this.indentation);
|
||||
}
|
||||
|
||||
public parse(contents: string): TranslationCollection {
|
||||
const values: {} = flat.flatten(JSON.parse(contents));
|
||||
const values: {} = flatten(JSON.parse(stripBOM(contents)));
|
||||
return new TranslationCollection(values);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user