96 lines
2.2 KiB
JavaScript

import { useDocument } from '@terrace/core'
import { createStringReader } from '@terrace/core/readers/js-string'
const lines = [
`name @terrace/core`,
`version 0.0.1`,
`randomthing test`,
`license MIT`,
`license GPL`,
`exports`,
` .`,
` import ./dist/index.js`,
` require ./dist/index.cjs`,
` ./parser`,
` import ./dist/parser.js`,
` require ./dist/parser.cjs`,
``,
` ./document`,
` import ./dist/document.js`,
` require ./dist/document.cjs`,
``,
` ./readers/node-readline`,
` import ./dist/readers/node-readline.js`,
` require ./dist/readers/node-readline.cjs`,
``,
` ./readers/js-string`,
` import ./dist/readers/js-string.js`,
` require ./dist/readers/js-string.cjs`,
`scripts`,
` test vitest ./src`,
` build vite build`,
`devDependencies`,
` vite ^3.2.3`,
` vitest ^0.24.5`,
``,
`authors`,
` author`,
` name Joshua Bemenderfer`,
` email josh@thederf.com`,
` `,
` Further comments below. As I will now demonstrate, there is no simple`,
` even if embedded`,
` way of dealing with this problem.`,
` author`,
` name Second Person`,
` email second@secondperson.com`,
` More text,`,
` across two lines.`,
`list`,
` - item1`,
` - item2`
]
// 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 { toLineArray } = useDocument(createStringReader(lines))
console.dir(await toLineArray(), { depth: null })
const { head, tail, each, match, toArray, toObject } = useDocument(createStringReader(lines))
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(),
'authors': () => toArray({
'author': () => toObject({ name: true, email: true, '#text': true })
}),
})
console.dir(structure, { depth: null })
}
main()