json-light
Version:
Allow to extend yaml or json files configuration
62 lines • 3.69 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable no-template-curly-in-string */
const __1 = require("..");
let data;
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
data = {
name: 'Spain',
region: 'Europe',
phoneCode: '34',
timezones: [
{ name: 'Madrid', offset: 1, pos: { lat: 40.4165, log: -3.70256 } },
{ name: 'Ceuta', offset: 1, pos: { lat: 35.8883, log: -5.3162 } },
{ name: 'Canary', offset: 0, pos: { lat: 28.1248, log: -15.43 } }
]
};
}));
describe('simple', () => {
test('resolve', () => {
const result = __1.JsonLight.type(data);
const expected = '{name:string,region:string,phoneCode:string,timezones:[{name:string,offset:integer,pos:{lat:decimal,log:decimal}}]}';
expect(expected).toStrictEqual(result);
});
test('compressed', () => {
const type = __1.JsonLight.type(data);
const result = __1.JsonLight.compress(data, { type });
const expected = '{"_":["Spain","Europe","34"],"timezones":[{"_":["Madrid",1],"pos":[40.4165,-3.70256]},{"_":["Ceuta",1],"pos":[35.8883,-5.3162]},{"_":["Canary",0],"pos":[28.1248,-15.43]}]}';
expect(expected).toStrictEqual(JSON.stringify(result));
});
test('decompress', () => {
const type = __1.JsonLight.type(data);
const compressed = __1.JsonLight.compress(data, { type });
const result = __1.JsonLight.decompress(compressed, { type });
const expected = '{"name":"Spain","region":"Europe","phoneCode":"34","timezones":[{"name":"Madrid","offset":1,"pos":{"lat":40.4165,"log":-3.70256}},{"name":"Ceuta","offset":1,"pos":{"lat":35.8883,"log":-5.3162}},{"name":"Canary","offset":0,"pos":{"lat":28.1248,"log":-15.43}}]}';
expect(expected).toStrictEqual(JSON.stringify(result));
});
});
describe('mapping', () => {
test('compressed', () => {
const type = __1.JsonLight.type(data);
const result = __1.JsonLight.compress(data, { type, mapping: true });
const expected = '{"0":[{"1":[40.4165,-3.70256],"_":["Madrid",1]},{"1":[35.8883,-5.3162],"_":["Ceuta",1]},{"1":[28.1248,-15.43],"_":["Canary",0]}],"_":["Spain","Europe","34"],"__map":{"0":"timezones","1":"pos"}}';
expect(expected).toStrictEqual(JSON.stringify(result));
});
test('decompress', () => {
const type = __1.JsonLight.type(data);
const compressed = __1.JsonLight.compress(data, { type, mapping: true });
const result = __1.JsonLight.decompress(compressed, { type });
const expected = '{"name":"Spain","region":"Europe","phoneCode":"34","timezones":[{"name":"Madrid","offset":1,"pos":{"lat":40.4165,"log":-3.70256}},{"name":"Ceuta","offset":1,"pos":{"lat":35.8883,"log":-5.3162}},{"name":"Canary","offset":0,"pos":{"lat":28.1248,"log":-15.43}}]}';
expect(expected).toStrictEqual(JSON.stringify(result));
});
});
//# sourceMappingURL=country.test.js.map