cross-json
An npm module that reports property differences between JSON files. This can be useful to check whether your JSON-based internationalization files contain every translation key for every language, for instance.
Last updated 5 years ago by kdex. .
GPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cross-json 
SYNC missed versions from official npm registry.

cross-json

How it works

cross-json will deeply compare the property keys for every combination of two files that gets passed in the arguments. Please note that, in order to function properly, file A and file B will need to be compared twice: On the first run, we check if each of A's properties is available in B. The second time, we'll have to do the opposite. Only if this succeeds do A and B contain the exact same properties.

Usage example

For instance, this can be useful to check whether your JSON-based internationalization files contain each translation key for every language.

Suppose you have the following JSON files:

lang/en_US.json

{
	"TIME_DIFFERENCE": "{{ value }} {{ unit }} ago",
	"I18N": "internationalization"
}

lang/en_GB.json

{
	"TIME_DIFFERENCE": "{{ value }} {{ unit }} ago",
	"I18N": "internationalisation"
}

lang/de_DE.json

{
	"TIME_DIFFERENCE": "vor {{ value }} {{ unit }}",
	"I18N": "Internationalisierung"
}

lang/fr_FR.json

{
	"TIME_DIFFERENCE": "il y a {{ value }} {{ unit }}",
	"I18N": "internationalisation",
	"MAIN_MENU": "menu principal"
}

We can now deduce which property keys are missing in which file using cross-json and easily fix our translation issue:

API

The same can also be achieved using the cross-json API like so:

import { crossCompare } from "cross-json";
let directory = "~/dev/awesome-project/lang/";
let files = [
	`${directory}/de_DE.json`,
	`${directory}/en_GB.json`,
	`${directory}/en_US.json`,
	`${directory}/fr_FR.json`
];
(async () => {
	await crossCompare(...files);
})();

Documentation

At the moment, this project has an inline documentation using YUIDoc syntax.

Current Tags

  • 1.0.3                                ...           latest (5 years ago)

4 Versions

  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (7)

Copyright 2014 - 2016 © taobao.org |