markdown-magic 2.6.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -10
- package/cli.js +5 -82
- package/lib/block-parser-js.test.js +179 -0
- package/lib/block-parser.js +389 -0
- package/lib/{utils/new-parser.test.js → block-parser.test.js} +168 -50
- package/lib/cli.js +234 -0
- package/lib/cli.test.js +409 -0
- package/lib/defaults.js +12 -0
- package/lib/index.js +319 -184
- package/lib/index.test.js +11 -0
- package/lib/options-parser.js +498 -0
- package/lib/options-parser.test.js +1237 -0
- package/lib/process-contents.js +330 -0
- package/lib/process-file.js +34 -0
- package/lib/transforms/code.js +67 -22
- package/lib/transforms/file.js +13 -10
- package/lib/transforms/remote.js +9 -6
- package/lib/transforms/toc.js +136 -64
- package/lib/transforms/wordCount.js +5 -0
- package/lib/utils/fs.js +340 -0
- package/lib/utils/fs.test.js +268 -0
- package/lib/utils/html-to-json/compat.js +42 -0
- package/lib/utils/html-to-json/format.js +64 -0
- package/lib/utils/html-to-json/index.js +37 -0
- package/lib/utils/html-to-json/lexer.js +345 -0
- package/lib/utils/html-to-json/parser.js +146 -0
- package/lib/utils/html-to-json/stringify.js +37 -0
- package/lib/utils/html-to-json/tags.js +171 -0
- package/lib/utils/index.js +19 -0
- package/{cli-utils.js → lib/utils/load-config.js} +2 -6
- package/lib/utils/logs.js +89 -0
- package/lib/utils/md/filters.js +20 -0
- package/lib/utils/md/find-code-blocks.js +80 -0
- package/lib/utils/md/find-date.js +32 -0
- package/lib/utils/md/find-frontmatter.js +94 -0
- package/lib/utils/md/find-frontmatter.test.js +17 -0
- package/lib/utils/md/find-html-tags.js +105 -0
- package/lib/utils/md/find-images.js +102 -0
- package/lib/utils/md/find-links.js +202 -0
- package/lib/utils/md/find-unmatched-html-tags.js +33 -0
- package/lib/utils/md/fixtures/2022-01-22-date-in-filename.md +14 -0
- package/lib/utils/md/fixtures/file-with-frontmatter.md +32 -0
- package/lib/utils/md/fixtures/file-with-links.md +143 -0
- package/lib/utils/md/md.test.js +37 -0
- package/lib/utils/md/parse.js +122 -0
- package/lib/utils/md/utils.js +19 -0
- package/lib/utils/regex-timeout.js +83 -0
- package/lib/utils/regex.js +38 -5
- package/lib/utils/remoteRequest.js +54 -0
- package/lib/utils/syntax.js +79 -0
- package/lib/utils/text.js +260 -0
- package/lib/utils/text.test.js +311 -0
- package/package.json +25 -25
- package/index.js +0 -46
- package/lib/processFile.js +0 -154
- package/lib/transforms/index.js +0 -114
- package/lib/updateContents.js +0 -125
- package/lib/utils/_md.test.js +0 -63
- package/lib/utils/new-parser.js +0 -412
- package/lib/utils/weird-parse.js +0 -230
- package/lib/utils/weird-parse.test.js +0 -217
package/lib/utils/weird-parse.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
const { parseJSON } = require('json-alexander')
|
|
2
|
-
|
|
3
|
-
function convert(value) {
|
|
4
|
-
if (value === 'false') {
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
if (value === 'true') {
|
|
8
|
-
return true
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const isNumber = Number(value)
|
|
12
|
-
if (typeof isNumber === 'number' && !isNaN(isNumber)) {
|
|
13
|
-
return isNumber
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// console.log(typeof value)
|
|
17
|
-
// console.log('value', value)
|
|
18
|
-
try {
|
|
19
|
-
const val = parseJSON(value) // last attempt to format an array like [ one, two ]
|
|
20
|
-
if (typeof val === 'string' && val.match(/^\[/) && val.match(/\]$/)) {
|
|
21
|
-
const inner = val.match(/^\[(.*)\]/)
|
|
22
|
-
if (inner && inner[1]) {
|
|
23
|
-
const newVal = inner[1].split(', ').map((x) => {
|
|
24
|
-
return convert(x.trim())
|
|
25
|
-
})
|
|
26
|
-
return newVal
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return val
|
|
30
|
-
} catch (err) {
|
|
31
|
-
console.log('val', value)
|
|
32
|
-
console.log('err', err)
|
|
33
|
-
}
|
|
34
|
-
return value
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const RESERVED = '__private'
|
|
38
|
-
|
|
39
|
-
function doWeirdParse(x) {
|
|
40
|
-
// https://regex101.com/r/bx8DXm/1/ Match everything but spaces/newlines
|
|
41
|
-
var y = /("|'|{)[^"}]+("|'|})|(\S+)/g
|
|
42
|
-
|
|
43
|
-
const cleanLines = x
|
|
44
|
-
.split(/\n/)
|
|
45
|
-
.filter((line) => {
|
|
46
|
-
// Trim all comment blocks
|
|
47
|
-
return !line.trim().match(/^(\/\/+|\/\*+|#+)/gm)
|
|
48
|
-
})
|
|
49
|
-
.join('\n')
|
|
50
|
-
|
|
51
|
-
var lines = cleanLines.match(y)
|
|
52
|
-
// console.log('lines', lines.length)
|
|
53
|
-
// console.log('lines', lines)
|
|
54
|
-
var isEnding = /(['"}\]]|true,?|false,?)$/
|
|
55
|
-
|
|
56
|
-
const values = lines.reduce((acc, curr, i) => {
|
|
57
|
-
const isLastLoop = lines.length === (i + 1)
|
|
58
|
-
const nextItem = lines[i + 1] || ''
|
|
59
|
-
const hasText = curr.match(/^[A-Za-z]/)
|
|
60
|
-
let alreadyAdded = false
|
|
61
|
-
|
|
62
|
-
/*
|
|
63
|
-
console.log('isLastLoop', isLastLoop)
|
|
64
|
-
console.log('RESERVED', acc[RESERVED])
|
|
65
|
-
console.log("current item", curr)
|
|
66
|
-
console.log('next item ', nextItem)
|
|
67
|
-
/** */
|
|
68
|
-
|
|
69
|
-
// If has no = its a true boolean. e.g isThingy
|
|
70
|
-
if (hasText && acc[RESERVED].match(/^[A-Za-z]/) && !isValuePair(acc[RESERVED])) {
|
|
71
|
-
// console.log('xxxxxxx', acc[RESERVED])
|
|
72
|
-
acc[trimTrailingComma(acc[RESERVED])] = true
|
|
73
|
-
acc[RESERVED] = ''
|
|
74
|
-
}
|
|
75
|
-
// If has no = its a true boolean
|
|
76
|
-
if (hasText && !curr.match(isEnding) && acc[RESERVED].match(isEnding)) {
|
|
77
|
-
// console.log('end', curr)
|
|
78
|
-
const kv = getKeyAndValueFromString(acc[RESERVED])
|
|
79
|
-
if (kv) {
|
|
80
|
-
acc[kv.key] = kv.value
|
|
81
|
-
}
|
|
82
|
-
acc[RESERVED] = ''
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (!acc[RESERVED].match(/^[A-Za-z]+={+/) && isValuePair(curr) && curr.match(isEnding)) {
|
|
86
|
-
const kv = getKeyAndValueFromString(curr)
|
|
87
|
-
if (kv) {
|
|
88
|
-
// console.log(`ADDED`, kv)
|
|
89
|
-
acc[kv.key] = kv.value
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
// console.log('Add', curr)
|
|
93
|
-
alreadyAdded = true
|
|
94
|
-
acc[RESERVED] = acc[RESERVED] + curr
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (acc[RESERVED].match(isEnding) && nextItem.match(/^[A-Za-z0-9_-]/)) {
|
|
99
|
-
const kv = getKeyAndValueFromString(acc[RESERVED])
|
|
100
|
-
if (kv) {
|
|
101
|
-
// console.log(`acc[RESERVED].match(isEnding)`, kv)
|
|
102
|
-
acc[kv.key] = kv.value
|
|
103
|
-
}
|
|
104
|
-
acc[RESERVED] = ''
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// If ends in number foo=2 or bar=3,
|
|
108
|
-
if (isValuePair(curr) && curr.match(/\d,?$/)) {
|
|
109
|
-
const kv = getKeyAndValueFromString(acc[RESERVED])
|
|
110
|
-
if (kv) {
|
|
111
|
-
// console.log(`acc[RESERVED].match(isEnding)`, kv)
|
|
112
|
-
acc[kv.key] = kv.value
|
|
113
|
-
}
|
|
114
|
-
acc[RESERVED] = ''
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// If last loop and still no match and looks like KV. Parse it
|
|
118
|
-
if (isLastLoop) {
|
|
119
|
-
// If single isCool boolean
|
|
120
|
-
if (hasText && !curr.match(/=/)) {
|
|
121
|
-
// console.log(`ADDED`, kv)
|
|
122
|
-
// acc[curr] = true
|
|
123
|
-
// acc[RESERVED] = ''
|
|
124
|
-
}
|
|
125
|
-
// console.log('currrrrr', curr)
|
|
126
|
-
// console.log("acc[RESERVED]", acc[RESERVED])
|
|
127
|
-
// console.log('combined', acc[RESERVED] + curr)
|
|
128
|
-
// If value empty but __private have accumulated values
|
|
129
|
-
if (acc[RESERVED]) {
|
|
130
|
-
// if (acc[RESERVED] && (acc[RESERVED].match(isEnding) || isValuePair(acc[RESERVED]))) {
|
|
131
|
-
const valueToCheck = (curr.match(isEnding) && !alreadyAdded) ? acc[RESERVED] + curr : acc[RESERVED]
|
|
132
|
-
// console.log('valueToCheck', valueToCheck)
|
|
133
|
-
const kv = getKeyAndValueFromString(valueToCheck)
|
|
134
|
-
if (kv) {
|
|
135
|
-
// console.log(`acc[RESERVED].match(isEnding)`, kv)
|
|
136
|
-
acc[kv.key] = kv.value
|
|
137
|
-
}
|
|
138
|
-
acc[RESERVED] = ''
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return acc
|
|
143
|
-
}, {
|
|
144
|
-
[RESERVED]: '',
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
delete values[RESERVED]
|
|
148
|
-
|
|
149
|
-
/* // If no keys last attempt to parse
|
|
150
|
-
if (!Object.keys(values).length) {
|
|
151
|
-
const kv = getKeyAndValueFromString(x)
|
|
152
|
-
if (kv) {
|
|
153
|
-
return {
|
|
154
|
-
[`${kv.key}`]: kv.value
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
*/
|
|
159
|
-
|
|
160
|
-
return values
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function isValuePair(str) {
|
|
164
|
-
return str.match(/=/)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// https://melvingeorge.me/blog/check-if-string-contain-emojis-javascript OR https://www.npmjs.com/package/emoji-regex
|
|
168
|
-
function hasEmoji(str) {
|
|
169
|
-
const regexExp = /^(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/gi;
|
|
170
|
-
return regexExp.test(str)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function getKeyAndValueFromString(string) {
|
|
174
|
-
if (!string) return
|
|
175
|
-
// const keyValueRegex = /([A-Za-z-_$]+)=['{"]?(.*)['}"]?/g
|
|
176
|
-
// const match = keyValueRegex.exec(string)
|
|
177
|
-
// if (!match) {
|
|
178
|
-
// return
|
|
179
|
-
// }
|
|
180
|
-
// console.log('getKeyAndValueFromString')
|
|
181
|
-
|
|
182
|
-
const [key, ...values] = string.split('=')
|
|
183
|
-
/* If no key or key starts with --- */
|
|
184
|
-
if (!key || key.charAt(0) === '-' || hasEmoji(key)) {
|
|
185
|
-
return
|
|
186
|
-
}
|
|
187
|
-
// console.log('string', string)
|
|
188
|
-
// console.log('key', key)
|
|
189
|
-
// console.log('values', values)
|
|
190
|
-
/* If no value, isThing === true */
|
|
191
|
-
if (!values.length) {
|
|
192
|
-
return {
|
|
193
|
-
key: key,
|
|
194
|
-
value: true,
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const value = values.join('')
|
|
199
|
-
|
|
200
|
-
let cleanValue = value
|
|
201
|
-
.replace(/^{{2,}/, '{')
|
|
202
|
-
.replace(/}{2,}$/, '}')
|
|
203
|
-
.replace(/^\[{2,}/, '[')
|
|
204
|
-
.replace(/\]{2,}$/, ']')
|
|
205
|
-
// Trim trailing commas
|
|
206
|
-
.replace(/,$/, '')
|
|
207
|
-
|
|
208
|
-
if (value.match(/^{[^:,]*}/)) {
|
|
209
|
-
cleanValue = removeSurroundingBrackets(cleanValue)
|
|
210
|
-
} else if (value.match(/^{\s*\[\s*[^:]*\s*\]\s*\}/)) {
|
|
211
|
-
// Match { [ one, two ,3,4 ] }
|
|
212
|
-
cleanValue = removeSurroundingBrackets(cleanValue)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return {
|
|
216
|
-
key: key,
|
|
217
|
-
value: convert(cleanValue),
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function trimTrailingComma(str = '') {
|
|
222
|
-
// Trim trailing commas
|
|
223
|
-
return str.replace(/,$/, '')
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function removeSurroundingBrackets(val) {
|
|
227
|
-
return val.replace(/^{/, '').replace(/}$/, '')
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
module.exports = doWeirdParse
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
const { test } = require('uvu')
|
|
2
|
-
const assert = require('uvu/assert')
|
|
3
|
-
const weirdParse = require('./weird-parse')
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const bigExample = `width={999}
|
|
7
|
-
height={{111}}
|
|
8
|
-
numberAsString="12345"
|
|
9
|
-
great={["scoot", "sco ot", 'scooo ttt']}
|
|
10
|
-
nice={{ value: nice, cool: "true" }}
|
|
11
|
-
soclose=[jdjdjd, hdhfhfhffh]
|
|
12
|
-
rad="boss"
|
|
13
|
-
cool=true notCool=false
|
|
14
|
-
nooooo={[one, two, 3, 4]}
|
|
15
|
-
numberZero=0,
|
|
16
|
-
xyz=999,
|
|
17
|
-
nope=false,
|
|
18
|
-
// comment
|
|
19
|
-
yes={true}
|
|
20
|
-
isWhat,
|
|
21
|
-
/* comment */
|
|
22
|
-
foo={{ rad: ["whatever", "man"], cool: { beans: 'here' } }}
|
|
23
|
-
# other comment
|
|
24
|
-
what='xnxnx'
|
|
25
|
-
isLoading
|
|
26
|
-
whatever={{ chill: "https://app.netlify.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna", pill: ['yo']}}
|
|
27
|
-
href="https://fooo.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna"
|
|
28
|
-
src="https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg"
|
|
29
|
-
deep={{ rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }}`
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
test('Multi line', () => {
|
|
33
|
-
const parsedValue = weirdParse(bigExample)
|
|
34
|
-
// console.log('parsedValue', parsedValue)
|
|
35
|
-
assert.equal(parsedValue, {
|
|
36
|
-
width: 999,
|
|
37
|
-
height: 111,
|
|
38
|
-
numberAsString: "12345",
|
|
39
|
-
great: [ 'scoot', 'sco ot', 'scooo ttt' ],
|
|
40
|
-
nice: { value: 'nice', cool: 'true' },
|
|
41
|
-
soclose: [ 'jdjdjd', 'hdhfhfhffh' ],
|
|
42
|
-
rad: 'boss',
|
|
43
|
-
cool: true,
|
|
44
|
-
notCool: false,
|
|
45
|
-
nooooo: [ 'one', 'two', 3, 4 ],
|
|
46
|
-
numberZero: 0,
|
|
47
|
-
xyz: 999,
|
|
48
|
-
nope: false,
|
|
49
|
-
yes: true,
|
|
50
|
-
isWhat: true,
|
|
51
|
-
foo: { rad: [ 'whatever', 'man' ], cool: { beans: 'here' } },
|
|
52
|
-
what: 'xnxnx',
|
|
53
|
-
isLoading: true,
|
|
54
|
-
whatever: {
|
|
55
|
-
chill: 'https://app.netlify.com/start/deploy?repositoryhttps://github.com/netlify/netlify-faunadb-example&stackfauna',
|
|
56
|
-
pill: [ 'yo' ]
|
|
57
|
-
},
|
|
58
|
-
href: 'https://fooo.com/start/deploy?repositoryhttps://github.com/netlify/netlify-faunadb-example&stackfauna',
|
|
59
|
-
src: 'https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg',
|
|
60
|
-
deep: { rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }
|
|
61
|
-
}, 'matches original')
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const testSpacing = `width={999}
|
|
65
|
-
height={{111}}
|
|
66
|
-
numberAsString="12345"
|
|
67
|
-
great={["scoot", "sco ot", 'scooo ttt']}
|
|
68
|
-
nope=false,
|
|
69
|
-
// comment
|
|
70
|
-
yes={true}
|
|
71
|
-
isWhat,
|
|
72
|
-
/* comment */
|
|
73
|
-
foo={{ rad: ["whatever", "man"], cool: { beans: 'here' } }}
|
|
74
|
-
# other comment
|
|
75
|
-
what='xnxnx'
|
|
76
|
-
isLoading
|
|
77
|
-
href="https://fooo.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna"
|
|
78
|
-
src="https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg"
|
|
79
|
-
deep={{ rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }}
|
|
80
|
-
`
|
|
81
|
-
|
|
82
|
-
// Verify indentation doesnt matter
|
|
83
|
-
test('Multi line indent', () => {
|
|
84
|
-
const parsedValue = weirdParse(testSpacing)
|
|
85
|
-
// console.log('parsedValue', parsedValue)
|
|
86
|
-
assert.equal(parsedValue, {
|
|
87
|
-
width: 999,
|
|
88
|
-
height: 111,
|
|
89
|
-
numberAsString: '12345',
|
|
90
|
-
great: [ 'scoot', 'sco ot', 'scooo ttt' ],
|
|
91
|
-
nope: false,
|
|
92
|
-
yes: true,
|
|
93
|
-
isWhat: true,
|
|
94
|
-
foo: { rad: [ 'whatever', 'man' ], cool: { beans: 'here' } },
|
|
95
|
-
what: 'xnxnx',
|
|
96
|
-
isLoading: true,
|
|
97
|
-
href: 'https://fooo.com/start/deploy?repositoryhttps://github.com/netlify/netlify-faunadb-example&stackfauna',
|
|
98
|
-
src: 'https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg',
|
|
99
|
-
deep: { rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }
|
|
100
|
-
}, 'matches original')
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
test('Single line', () => {
|
|
104
|
-
const parsedValue = weirdParse(`width={999} height={{111}} numberAsString="12345" great={["scoot", "sco ot", 'scooo ttt']} nice={{ value: nice, cool: "true" }} soclose=[jdjdjd, hdhfhfhffh] rad="boss" cool=true isCool notCool=false nooooo={[one, two, 3, 4]}`)
|
|
105
|
-
console.log('parsedValue', parsedValue)
|
|
106
|
-
assert.equal(parsedValue, {
|
|
107
|
-
width: 999,
|
|
108
|
-
height: 111,
|
|
109
|
-
numberAsString: '12345',
|
|
110
|
-
great: [ 'scoot', 'sco ot', 'scooo ttt' ],
|
|
111
|
-
nice: { value: 'nice', cool: 'true' },
|
|
112
|
-
soclose: [ 'jdjdjd', 'hdhfhfhffh' ],
|
|
113
|
-
rad: 'boss',
|
|
114
|
-
cool: true,
|
|
115
|
-
isCool: true,
|
|
116
|
-
notCool: false,
|
|
117
|
-
nooooo: [ 'one', 'two', 3, 4 ]
|
|
118
|
-
}, 'matches original')
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
test('Simple string equal (single quotes)', () => {
|
|
122
|
-
const parsedValue = weirdParse(`bob='cool'`)
|
|
123
|
-
assert.equal(parsedValue, {
|
|
124
|
-
bob: 'cool',
|
|
125
|
-
})
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
test('Simple string equal (double quotes)', () => {
|
|
129
|
-
const parsedValue = weirdParse(`bob="cool"`)
|
|
130
|
-
assert.equal(parsedValue, {
|
|
131
|
-
bob: 'cool',
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
test('Simple string equal (no quotes)', () => {
|
|
136
|
-
const parsedValue = weirdParse(`bob=cool`)
|
|
137
|
-
// console.log('parsedValue', parsedValue)
|
|
138
|
-
assert.equal(parsedValue, {
|
|
139
|
-
bob: 'cool',
|
|
140
|
-
})
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
test('Simple string equal (no quotes with spaces)', () => {
|
|
144
|
-
const answer = { bob: 'cool' }
|
|
145
|
-
const one = weirdParse(`bob = cool`)
|
|
146
|
-
const two = weirdParse(`bob= cool`)
|
|
147
|
-
const three = weirdParse(`bob =cool`)
|
|
148
|
-
// console.log('parsedValue', parsedValue)
|
|
149
|
-
assert.equal(one, answer)
|
|
150
|
-
assert.equal(two, answer)
|
|
151
|
-
assert.equal(three, answer)
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
test('Simple boolean', () => {
|
|
155
|
-
const answer = { isCool: true }
|
|
156
|
-
const one = weirdParse(`isCool`)
|
|
157
|
-
const two = weirdParse(`isCool = true`)
|
|
158
|
-
const three = weirdParse(`isCool =true`)
|
|
159
|
-
const four = weirdParse(`isCool=true`)
|
|
160
|
-
const fourx = weirdParse(`isCool={true}`)
|
|
161
|
-
const foury = weirdParse(`isCool={{true}}`)
|
|
162
|
-
|
|
163
|
-
assert.equal(one, answer)
|
|
164
|
-
assert.equal(two, answer)
|
|
165
|
-
assert.equal(three, answer)
|
|
166
|
-
assert.equal(four, answer)
|
|
167
|
-
assert.equal(fourx, answer)
|
|
168
|
-
assert.equal(foury, answer)
|
|
169
|
-
|
|
170
|
-
const answerTwo = { isNotCool: false }
|
|
171
|
-
const five = weirdParse(`isNotCool=false`)
|
|
172
|
-
const six = weirdParse(`isNotCool = false`)
|
|
173
|
-
const seven = weirdParse(`isNotCool =false`)
|
|
174
|
-
const eight = weirdParse(`isNotCool=false`)
|
|
175
|
-
const nine = weirdParse(`isNotCool= false`)
|
|
176
|
-
const ten = weirdParse(`isNotCool={false}`)
|
|
177
|
-
const eleven = weirdParse(`isNotCool={{false}}`)
|
|
178
|
-
|
|
179
|
-
assert.equal(five, answerTwo, 'five')
|
|
180
|
-
assert.equal(six, answerTwo, 'six')
|
|
181
|
-
assert.equal(seven, answerTwo, 'seven')
|
|
182
|
-
assert.equal(eight, answerTwo, 'eight')
|
|
183
|
-
assert.equal(nine, answerTwo, 'nine')
|
|
184
|
-
assert.equal(ten, answerTwo, 'ten')
|
|
185
|
-
assert.equal(eleven, answerTwo, 'eleven')
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
test('Simple object', () => {
|
|
189
|
-
const a = { key: { a: 'b' }}
|
|
190
|
-
assert.equal(a, weirdParse(`key={{ "a": "b" }}`))
|
|
191
|
-
assert.equal(a, weirdParse(`key={{ "a": b }}`))
|
|
192
|
-
assert.equal(a, weirdParse(`key={{ a: "b" }}`))
|
|
193
|
-
assert.equal(a, weirdParse(`key={{ a: b }}`))
|
|
194
|
-
assert.equal(a, weirdParse(`key={ a : b }`), 'single {')
|
|
195
|
-
|
|
196
|
-
const answer = { nice: { value: 'nice', cool: 'true', awesome: false } }
|
|
197
|
-
const one = weirdParse(`nice={{ value: nice, cool: "true", awesome: false }}`)
|
|
198
|
-
assert.equal(one, answer)
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
test('Simple array', () => {
|
|
202
|
-
const x = { key: [ 1, 2, 3 ] }
|
|
203
|
-
const y = weirdParse(`key=[ 1, 2, 3 ]`)
|
|
204
|
-
assert.equal(x, y)
|
|
205
|
-
|
|
206
|
-
const z = weirdParse(`key=[ "1", "2", "3" ]`)
|
|
207
|
-
assert.equal(z, { key: [ "1", "2", "3" ] })
|
|
208
|
-
|
|
209
|
-
const a = weirdParse(`key=[ one, two, three ]`)
|
|
210
|
-
assert.equal(a, { key: [ "one", "two", "three" ] })
|
|
211
|
-
|
|
212
|
-
const answer = { great: [ 'scoot', 'sco ot', 'scooo ttt', 'one', 'two', 3, 4, true ] }
|
|
213
|
-
const one = weirdParse(`great={["scoot", "sco ot", 'scooo ttt', one, two, 3, 4, true]} `)
|
|
214
|
-
assert.equal(one, answer)
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
test.run()
|