More API cleanup in preparation for a DSL.
This commit is contained in:
@@ -40,52 +40,43 @@ const lines = [
|
||||
` Further comments below. As I will now demonstrate, there is no simple`,
|
||||
` even if embedded`,
|
||||
` way of dealing with this problem.`,
|
||||
``
|
||||
]
|
||||
|
||||
// Schema
|
||||
// name tail
|
||||
// version tail
|
||||
// license tail
|
||||
// exports object
|
||||
// #any object
|
||||
// import tail
|
||||
// require tail
|
||||
// scripts object
|
||||
// #any tail
|
||||
// devDependencies
|
||||
// #any tail
|
||||
// author object
|
||||
// name tail
|
||||
// email tail
|
||||
// #text
|
||||
|
||||
|
||||
async function main() {
|
||||
const { toArrays } = useDocument(createStringReader(lines))
|
||||
const resultArrays = await toArrays()
|
||||
console.dir(resultArrays, { depth: null })
|
||||
const { toLineArray } = useDocument(createStringReader(lines))
|
||||
console.dir(await toLineArray(), { depth: null })
|
||||
|
||||
const { tail, each, match, buildObject } = useDocument(createStringReader(lines))
|
||||
const { head, tail, each, match, toObject } = useDocument(createStringReader(lines))
|
||||
|
||||
const structure = {
|
||||
name: null,
|
||||
version: null,
|
||||
license: null,
|
||||
exports: null,
|
||||
scripts: null,
|
||||
devDependencies: null,
|
||||
author: null
|
||||
}
|
||||
|
||||
await each(async () => {
|
||||
if (match('name')) structure.name = tail().trim()
|
||||
if (match('version')) structure.version = tail().trim()
|
||||
if (match('license')) structure.license = tail().trim()
|
||||
// FIXME: Order of operations causes other parts to break if this doesn't run first?!
|
||||
if (match('exports')) structure.exports = await buildObject([], async () => {
|
||||
const section = { import: null, require: null }
|
||||
|
||||
await each(() => {
|
||||
if (match('import')) section.import = tail().trim()
|
||||
if (match('require')) section.require = tail().trim()
|
||||
if (section.import && section.require) return true
|
||||
})
|
||||
|
||||
return section
|
||||
})
|
||||
if (match('scripts')) structure.scripts = await buildObject()
|
||||
if (match('devDependencies')) structure.devDependencies = await buildObject()
|
||||
if (match('author')) structure.author = await buildObject(['name', 'email', '#text'])
|
||||
|
||||
return structure.name &&
|
||||
structure.version &&
|
||||
structure.license &&
|
||||
structure.exports &&
|
||||
structure.scripts &&
|
||||
structure.devDependencies &&
|
||||
structure.author
|
||||
const structure = await toObject({
|
||||
'name': true,
|
||||
'version': () => tail().trim(),
|
||||
'license': () => tail().trim(),
|
||||
'exports': () => toObject({
|
||||
'#any': () => toObject({ import: true, require: true })
|
||||
}),
|
||||
'scripts': () => toObject({ '#any': true }),
|
||||
'devDependencies': () => toObject(),
|
||||
'author': () => toObject({ name: true, email: true, '#text': true })
|
||||
})
|
||||
|
||||
console.dir(structure, { depth: null })
|
||||
|
||||
Reference in New Issue
Block a user