modl-converter
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -11,5 +11,5 @@ "use strict"; | ||
var jsonToModl = JsonToModl_1.createJsonToModl(); | ||
var modlString = 'Hello=World'; | ||
var jsonString = '{"Hello":"World"}'; | ||
var modlString = '[a;` `]'; | ||
var jsonString = '["a", " "]'; | ||
chai_1.expect(jsonToModl.stringToModl(jsonString)).equal(modlString); | ||
//# sourceMappingURL=scratch.js.map |
@@ -21,3 +21,9 @@ "use strict"; | ||
if (s !== null && | ||
(exports.shouldBeGraveQuoted.test(s) || s === '' || (exports.isNumeric.test(s) && s !== '00' && s !== '01' && s !== '000') || 'true' === s || 'false' === s || 'null' === s)) { | ||
(exports.shouldBeGraveQuoted.test(s) || | ||
s === '' || | ||
(exports.isNumeric.test(s) && s !== '00' && s !== '01' && s !== '000') || | ||
'true' === s || | ||
'false' === s || | ||
'null' === s || | ||
isAllSpaces(s))) { | ||
return '`' + s + '`'; | ||
@@ -30,2 +36,5 @@ } | ||
exports.graveQuoteIfNecessary = graveQuoteIfNecessary; | ||
var isAllSpaces = function (s) { | ||
return s.trim().length === 0; | ||
}; | ||
var doubleQuoteIfNecessary = function (s) { return (s !== null && s.includes('~`') ? '"' + s + '"' : s); }; | ||
@@ -32,0 +41,0 @@ exports.doubleQuoteIfNecessary = doubleQuoteIfNecessary; |
{ | ||
"name": "modl-converter", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "A JSON to MODL library in TypeScript", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -1,11 +0,7 @@ | ||
# TypeScript JSON to MODL Library | ||
# JSON to MODL Library | ||
## TypeScript Example | ||
```TypeScript | ||
import { expect } from 'chai'; | ||
import loglevel from 'loglevel'; | ||
import { createJsonToModl } from './JsonToModl'; | ||
// Set the logging level | ||
loglevel.setLevel('DEBUG'); | ||
// Create a JSON to MODL converter | ||
@@ -20,4 +16,16 @@ const jsonToModl = createJsonToModl(); | ||
// Verify the result. Debug-level logging displays the result. | ||
expect(jsonToModl.stringToModl(jsonString)).equal(modlString); | ||
console.log(jsonToModl.stringToModl(jsonString)); | ||
``` | ||
## JavaScript Example | ||
```javascript | ||
const api = require('modl-converter'); | ||
// This is the expected result | ||
const modlString = 'Hello=World'; | ||
// This is the test data | ||
const jsonString = '{"Hello":"World"}'; | ||
console.log(api.jsonToModl.stringToModl(jsonString)); | ||
``` |
@@ -155,2 +155,5 @@ import log from 'loglevel'; | ||
} | ||
// | ||
// Handling for strings | ||
// | ||
if (typeof node === 'string') { | ||
@@ -157,0 +160,0 @@ if ('null' === node) { |
@@ -5,9 +5,13 @@ import { expect } from 'chai'; | ||
// Set the logging level | ||
loglevel.setLevel('DEBUG'); | ||
// Create a JSON to MODL converter | ||
const jsonToModl = createJsonToModl(); | ||
const modlString = 'Hello=World'; | ||
const jsonString = '{"Hello":"World"}'; | ||
// This is the expected result | ||
const modlString = '[a;` `]'; | ||
const jsonString = '["a", " "]'; | ||
// Verify the result. Debug-level logging displays the result. | ||
expect(jsonToModl.stringToModl(jsonString)).equal(modlString); |
@@ -26,3 +26,9 @@ import { createUnicodeEscaper } from './UnicodeEscaper'; | ||
s !== null && | ||
(shouldBeGraveQuoted.test(s) || s === '' || (isNumeric.test(s) && s !== '00' && s !== '01' && s !== '000') || 'true' === s || 'false' === s || 'null' === s) | ||
(shouldBeGraveQuoted.test(s) || | ||
s === '' || | ||
(isNumeric.test(s) && s !== '00' && s !== '01' && s !== '000') || | ||
'true' === s || | ||
'false' === s || | ||
'null' === s || | ||
isAllSpaces(s)) | ||
) { | ||
@@ -36,2 +42,10 @@ return '`' + s + '`'; | ||
/** | ||
* | ||
* @param s string | ||
* @returns true if the string is all spaces | ||
*/ | ||
const isAllSpaces = (s: string): boolean => { | ||
return s.trim().length === 0; | ||
}; | ||
/** | ||
* Some MODL string need backtick quotes. | ||
@@ -38,0 +52,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39282
630
30