Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Parse a Stringified example. #21

Closed
meyverick opened this issue May 26, 2022 · 2 comments
Closed

Can't Parse a Stringified example. #21

meyverick opened this issue May 26, 2022 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@meyverick
Copy link

I try to stringify the readme example and then parse it and it returns an error. Am I doing it wrong?

Script

import TOML from "@ltd/j-toml";

const test = TOML.stringify({
	key: "value",
	dotted: {
		key: "value",
	},
	inlineTable: TOML.inline({ key: "value" }),
	mix: {
		key: "value",
		table: TOML.Section({
			key: "value",
		}),
	},
	table: TOML.Section({
		key: "value",
		table: TOML.Section({
			key: "value",
		}),
	}),
});

const rootTable = TOML.parse(test);

Returns

PS C:\Users\User Name\Files\My Project\app> node helpers/configFile.js
file:///C:/Users/User%20Name/Files/My%20Project/app/node_modules/@ltd/j-toml/index.mjs:2230
    if ( typeof sourcePath!=='string' ) { throw TypeError$1('TOML.parse(source.path)'); }
                                                                            ^

TypeError: TOML.parse(source.path)
    at parse (file:///C:/Users/User%20Name/Files/My%20Project/app/node_modules/@ltd/j-toml/index.mjs:2230:49)
    at Module.parse (file:///C:/Users/User%20Name/Files/My%20Project/app/node_modules/@ltd/j-toml/index.mjs:2293:6)
    at file:///C:/Users/User%20Name/Files/V%20Rising/app/helpers/configFile.js:38:24
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async loadESM (node:internal/process/esm_loader:85:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Node.js v17.9.0
@LongTengDao LongTengDao added the question Further information is requested label Jun 9, 2022
@LongTengDao
Copy link
Owner

LongTengDao commented Jun 9, 2022

@meyverick Sorry for replying late. TOML.stringify returns an array of strings, if there is no options.newline, because the lib doesn't know use what to join lines.

See the docs:

  1. https://github.com/LongTengDao/j-toml/tree/master/docs/English#optionsnewline
  2. https://github.com/LongTengDao/j-toml/tree/master/docs/English#return-2

When you pass it into TOML.parse, it throws, because TOML.parse only accept string | Buffer | { path, data } currently.

I may (or may not) add this feature (parsing array of lines) in the future.

@LongTengDao LongTengDao added the enhancement New feature or request label Jun 9, 2022
@LongTengDao LongTengDao reopened this Jun 21, 2022
@LongTengDao LongTengDao pinned this issue Aug 11, 2022
@LongTengDao
Copy link
Owner

LongTengDao commented Aug 11, 2022

To help users to notice that TOML.stringify WON'T return string while there is no option newline, currently I don't add the feature that supporting parsing array of lines, and I make it more friendly to notice that since v1.33.0.

When users widely know the options.newline, I will add the feature of parsing array; or I found users will never remember that, then I may remove the feature that TOML.stringify returning array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants