GithubHelp home page GithubHelp logo

longtengdao / j-toml Goto Github PK

View Code? Open in Web Editor NEW
53.0 53.0 5.0 9.01 MB

A Node.js implementation of TOML written by LongTengDao. Belong to "Plan J"./龙腾道为汤小明语写的 Node.js 实现。从属于“简计划”。

Home Page: https://npmjs.com/package/@ltd/j-toml

License: GNU Lesser General Public License v3.0

JavaScript 7.45% TypeScript 92.55%
ecmascript javascript npm toml typescript

j-toml's People

Contributors

longtengdao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

j-toml's Issues

使用的时候遇到了一个报错

ERROR in ./node_modules/@ltd/j-toml/index.js 356:28
Module parse failed: Unexpected token (356:28)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
| class mark {
>                        lineIndex = lineIndex;
|                        type                                                                                           ;
|                        restColumn        ;

NULL prototype thing causes trouble

The parse method produces objects with a strange prototype. Rather than leaving it at Object.prototype (the default) or using null (mostly better), the objects get an indirect prototype, an object that itself has a null prototype, and is also sealed. I cannot imagine any valid reason for this: it’s purely inefficiency. But it also thwarts detection of a null prototype, which is a bad thing, because “is its prototype Object.prototype or null” is a customary “simple object” check. For a concrete example of what this breaks, trying to use require("@ltd/j-toml").parse in Eleventy data or front matter ends up ignoring everything if deep data merging is enabled (which it is by default), because it does this kind of “simple object” check, or uses the iteration prototcol if it isn’t simple—and this gets erroneously detected as not simple.

I propose removing this:

const NULL = (
	/* j-globals: null.prototype (internal) */
	Object.seal
		? /*#__PURE__*/Object.preventExtensions(Object.create(null))
		: null
	/* j-globals: null.prototype (internal) */
);

And replacing all occurrences of NULL with null. Simpler, faster, more efficient, less troublesome. There may be more related stuff to it, but I’ve decided not to use this library because of this and other troublesome prototype shenanigans (e.g. how Datetime effectively deletes methods, which is a bad thing to do and almost always worse than just not doing that—yeah, if you try accessing the “wrong” methods on LocalDate you’ll effectively get a T00:00:00Z, but that’s not so bad), so I haven’t delved particularly deeply.

Sample Node transcript showing the problem and a hacky postprocessing fix for the prototype (though you’d need to do this recursively):

> toml = require("@ltd/j-toml");
…
> data = toml.parse("key = 'value'")
Object <[Object: null prototype] {}> { key: 'value' }
> Object.getPrototypeOf(data)
[Object: null prototype] {}
> Object.setPrototypeOf(data, null)
[Object: null prototype] { key: 'value' }

Cannot use with Cypress - requires es2019 or lower?

Hi, thanks for writing this library!

When I try to use this in Cypress, I get an error very similar to #1

Here are the commands I run (MCVE):

cd $(mktemp -d)
npm init -y
# First time install may take a long time as it caches binaries
npm install cypress @ltd/j-toml
mkdir -p cypress/e2e

cat <<EOF > cypress.config.js
const { defineConfig } = require('cypress')
module.exports = defineConfig({e2e: { setupNodeEvents(on, config) {} , video: false, supportFile: false } })
EOF

cat <<EOF > cypress/e2e/test.cy.js
import TOML from "@ltd/j-toml";
const table = TOML.parse("", 1.0, "\n");
EOF

./node_modules/.bin/cypress run

I get:

Error: Webpack Compilation Error
./node_modules/@ltd/j-toml/index.js 629:28
Module parse failed: Unexpected token (629:28)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
| class mark {
>                        lineIndex = lineIndex;
|                        type                                                                                           ;
|                        restColumn        ;

I tried commenting out the 3 lines after class mark { and this shifted the error elsewhere, then there is some nullish coalescing (?? operator). It looks like index.js in j-toml is built with a newer syntax than whatever is supported by Cypress.

This comment suggests that it only supports es2019 - is it possible to build j-toml to target es2019 please?

TS7016: Could not find a declaration file for module '@ltd/j-toml'

Upgrading from v1.11.0 to v1.12.0 causes this TypeScript compiler error:

Error: src/config.ts(1,34): error TS7016: Could not find a declaration file for module '@ltd/j-toml'. '/home/runner/work/bootleg/bootleg/node_modules/@ltd/j-toml/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/ltd__j-toml` if it exists or add a new declaration (.d.ts) file containing `declare module '@ltd/j-toml';`

Is there a simple demo code to provide pretty format?

For example,my toml file like

[appearance]
custom_backaground_img = './custom_background_image.png'
custom_backaground_opacity = 0.44999998807907104
date_format = 'MM-dd-yyyy'
editor_theme = ''
language = 'zh-CHS'
theme = 'wheat'
time_format = 'HH:mm:ss '

[encryption]
enable_file_compress = true
entry_file_name = 'manifest.enc'
file_ext = '.enc'
master_password = ''

[normal]
show_file_saving_status = true
spell_check = false

[sync]
enable_fail_safe = true
interval_seconds = 5
max_concurrent_connections = 5
storage_type = 'aliyunOss'

[sync.aliyun_oss]
access_key_id = ''
access_key_secret = ''
bucket = ''
region = ''
url = ''

[sync.amazon_s3]
access_key = ''
bucket = ''
region = ''
secret_key = ''
url = ''

[sync.local_disk]
data_dir_path = ''

The output in console of parse is right,then I use stringify like :

    console.log(">>> toml :: ", stringifyToml(settingStore.setting, {
            newline: "\n",
            newlineAround: "section",
            xBeforeNewlineInMultilineTable: ","
        }))

The output will like:

normal.show_file_saving_status = true
normal.spell_check = false
appearance.language = ''
appearance.editor_theme = ''
appearance.date_format = ''
appearance.theme = ''
appearance.time_format = ''
appearance.custom_backaground_img = ''
appearance.custom_backaground_opacity = 0.8
sync.storage_type = ''
sync.amazon_s3.bucket = ''
sync.amazon_s3.url = ''
sync.amazon_s3.region = ''
sync.amazon_s3.access_key = ''
sync.amazon_s3.secret_key = ''
sync.aliyun_oss.bucket = ''
sync.aliyun_oss.url = ''
sync.aliyun_oss.region = ''
sync.aliyun_oss.access_key_id = ''
sync.aliyun_oss.access_key_secret = ''
sync.local_disk.data_dir_path = ''
sync.interval_seconds = 5.0
sync.enable_fail_safe = true
sync.max_concurrent_connections = 5.0
encryption.master_password = ''
encryption.entry_file_name = 'manifest.enc'
encryption.file_ext = '.enc'
encryption.enable_file_compress = true

How to make a pretty format?

Thank you

How can I define custom typescript type for parsed data?

I'm trying to use the following code:

TOML.parse<{ a: string; b: string }>(tomlSource, {
    joiner: "\n",
    bigint: false,
});

but this give the following error:

Argument of type '{ joiner: string; bigint: false; }' is not assignable to parameter of type '{ joiner?: string | undefined; bigint?: number | boolean | undefined; x: TagProcessor<{ a: string; b: string; }> | ({ readonly tag: TagProcessor<{ a: string; b: string; }>; readonly null?: boolean | undefined; } & TypeAgnosticOptions); }'.
Property 'x' is missing in type '{ joiner: string; bigint: false; }' but required in type '{ joiner?: string | undefined; bigint?: number | boolean | undefined; x: TagProcessor<{ a: string; b: string; }> | ({ readonly tag: TagProcessor<{ a: string; b: string; }>; readonly null?: boolean | undefined; } & TypeAgnosticOptions); }'.ts(2345)
index.d.ts(25, 194): 'x' is declared here.

So it asks me to define x: TagProcessor<{ a: string; b: string; }>.
What is this?

Thanks.

Controlling spaces in list output

Currently lists output like:

extensions = [ 'value' ]

I couldn't find an easy configuration option to control this spacing. Specifically I'm looking to achieve the output:

extensions = ['value']

If I've missed something in the docs please let me know.

Unexpected token in index.js

ERROR in ./node_modules/@ltd/j-toml/index.js 439:27
Module parse failed: Unexpected token (439:27)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See
https://webpack.js.org/concepts#loaders
|               weak.set = weak.set;
|               const properties = getOwnPropertyDescriptors(freeze(freeze(class extends Array$1 {
>                       static [Symbol.species] = class extends null { constructor () { return DELETED; } };
|                       constructor () { return super(); }
|                       get slice () { }
 @ ./src/pages/upload.tsx 14:0-35 22:15-25
 @ ./.cache/_this_is_virtual_fs_path_/$virtual/async-requires.js 26:11-28:5
 @ ./.cache/app.js 17:0-52 28:0-70 30:27-40 28:0-70

Code:

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

function parseToml(content) {
    try {
        const toml = TOML.parse(content, 1.0, "\n");
    } catch (e) {
        console.error(e);
    }
}

I'm not entirely sure what is going on here.
What information do you need to debug this?

Configure double quotes or single quotes output

I am using this project to parse / lint TOML files generated by Rust.

Rust uses double quotes to surround all of their strings. For example, when doing cargo init:

[package]
name = "temp"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

However, when using TOML.stringify, the default character used is a single quote.

let text = fs.readFileSync(file);
let toml = TOML.parse(text, { x: { comment: true } });
let new_text = TOML.stringify(toml, { newline: "\n", newlineAround: "section" });
fs.writeFileSync(file, new_text);

Output:

[package]
name = 'temp'
version = '0.1.0'
edition = '2021'

[dependencies]

Diff

diff --git a/Cargo.toml b/Cargo-new.toml
index 8dd49c0..dfc05d5 100644
--- a/Cargo.toml
+++ b/Cargo-new.toml
@@ -1,8 +1,7 @@
-[package]
-name = "temp"
-version = "0.1.0"
-edition = "2021"
 
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+[package]
+name = 'temp'
+version = '0.1.0'
+edition = '2021'
 
 [dependencies]

It would be nice to be able to configure this to keep things more consistent in Rust projects.

Status of Single-line and Multiline Comments

I have read in the documentation that that parsing and handling comments is one of the "sore points".

Specifically, it seems your library only parses and allows for inline comments, whereas it is pretty regular to see TOML files with comments over the lines they are modifying, or even multiline comments which act as separators between sections of TOML configuration.

Examples of comments over the lines can be found in the TOML specification: https://toml.io/en/

# integers
int1 = +99
int2 = 42
int3 = 0
int4 = -17

# hexadecimal with prefix `0x`
hex1 = 0xDEADBEEF
hex2 = 0xdeadbeef
hex3 = 0xdead_beef

# octal with prefix `0o`
oct1 = 0o01234567
oct2 = 0o755

And a basic Rust toml file uses an "island" comment:

[package]
name = "temp"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

In our project Substrate, we take advantage of multiline comments in toml like this:

# The list of dependencies below (which can be both direct and indirect dependencies) are crates
# that are suspected to be CPU-intensive, and that are unlikely to require debugging (as some of
# their debug info might be missing) or to require to be frequently recompiled. We compile these
# dependencies with `opt-level=3` even in "dev" mode in order to make "dev" mode more usable.
# The majority of these crates are cryptographic libraries.
#
# Note that this does **not** affect crates that depend on Substrate. In other words, if you add
# a dependency on Substrate, you have to copy-paste this list in your own `Cargo.toml` (assuming
# that you want the same list). This list is only relevant when running `cargo build` from within
# the Substrate workspace.
#
# If you see an error mentioning "profile package spec ... did not match any packages", it
# probably concerns this list.
#
# This list is ordered alphabetically.
[profile.dev.package]
blake2 = { opt-level = 3 }
blake2-rfc = { opt-level = 3 }
blake2b_simd = { opt-level = 3 }
chacha20poly1305 = { opt-level = 3 }
...

What are the current limitations around parsing and handling these TOML comments? Is this something that this library could support in the future?

If you have an idea how you would like it implemented, could you write some notes so maybe I (or others) could try a stab at it?

Thanks!

v1.16.0 breaks bundled javascript

Hello 👋

v1.16.0 introduces a static fs import in parse/.ts:8. This breaks any frontend bundling that isn't stubbing out node libraries. In a default esbuild run I now get:

 > node_modules/@ltd/j-toml/index.mjs:1:32: error: Could not resolve "fs" (use "platform: 'node'" when building for node)
    1 │ import { readFileSync } from 'fs';

Could this be changed to something like a dynamic import behind a try? Loosely something like:

let fs = { readFileSync: () => { throw Error("readFileSync unsupported outside of node"} } };
try {
    fs = await import('fs');
}

Or something behind a platform flag.

SyntaxError: Bad bare key at line 1

redevelopFile content:

template = 'RN_B2C'
checkout = 'support/seldon2'

using TOML.parse(redevelopFile, 1.0, '\r\n') error:

(node:84798) UnhandledPromiseRejectionWarning: SyntaxError: Bad bare key at line 1: /Users/hustcer/github/terminus/gaia-mobile/redevelop.b2c.toml
    at getKeys (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:696:101)
    at KEY_VALUE_PAIR_exec_groups (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:728:23)
    at assign (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:1818:46)
    at Root (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:1906:24)
    at Module.parse (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:1952:23)
    at module.exports (/Users/hustcer/github/terminus/mall-base/packages/mall-tools/src/commands/redevelop.js:293:44)
    at Command.<anonymous> (/Users/hustcer/github/terminus/mall-base/packages/mall-tools/src/cli/index.js:107:5)
    at Command.listener [as _actionHandler] (/Users/hustcer/github/terminus/mall-base/packages/mall-tools/node_modules/commander/lib/command.js:466:17)
    at /Users/hustcer/github/terminus/mall-base/packages/mall-tools/node_modules/commander/lib/command.js:1170:65
    at Command._chainOrCall (/Users/hustcer/github/terminus/mall-base/packages/mall-tools/node_modules/commander/lib/command.js:1088:12)

Stringify of the same JSON created via parse does not produce a valid TOML back

Description

I am trying to create a TOML parser node for the node-RED project where one can parse and stringify to and from TOML.

I am using this particular library to make the parser possible. The good news is that toml.parse() is working well and providing a valid javascript object.

I am using the standard mentioned on learnxinyminutes docs for TOML

# You can create nested arrays of tables as well. Each double-bracketed
# sub-table will belong to the nearest table element above it.

[[fruit]]
  name = "apple" # I am a property in fruit table/map

  [fruit.geometry]
    shape = "round"
    note = "I am a property in geometry table/map"

  [[fruit.color]]
    name = "red"
    note = "I am an array item in apple fruit's table/map"

  [[fruit.color]]
    name = "green"
    note = "I am in the same array as red"

[[fruit]]
  name = "banana"

  [[fruit.color]]
    name = "yellow"
    note = "I am an array item in banana fruit's table/map"

Upon passing this in the node-RED editor
image

the above mentioned TOML configuration is in the template node in the diagram, I am getting the following javascript object

{"fruit":[{"name":"apple","geometry":{"shape":"round","note":"I am a property in geometry table/map"},"color":[{"name":"red","note":"I am an array item in apple fruit's table/map"},{"name":"green","note":"I am in the same array as red"}]},{"name":"banana","color":[{"name":"yellow","note":"I am an array item in banana fruit's table/map"}]}]}

Problem

Now if were to take the same JSON result from above and let the TOML node stringify it for me via the node-RED editor I get the following result:

fruit = [
	{ name = 'apple', geometry.shape = 'round', geometry.note = 'I am a property in geometry table/map', color = [
		{ name = 'red', note = "I am an array item in apple fruit's table/map" },
		{ name = 'green', note = 'I am in the same array as red' },
	] },
	{ name = 'banana', color = [
		{ name = 'yellow', note = "I am an array item in banana fruit's table/map" },
	] },
]

If you pass the above toml to the a validator, the TOML is invalid.

The problem lies that the toml.stringify does not resolve the:

geometry.shape = 'round', geometry.note = 'I am a property in geometry table/map'

correctly.

Code

module.exports = function(RED) {
    "use strict";
    var toml = require('@ltd/j-toml');
    function TOMLNode(n) {
        RED.nodes.createNode(this,n);
        this.property = n.property||"payload";
        var node = this;
        this.on("input", function(msg,send,done) {
            var value = RED.util.getMessageProperty(msg,node.property);
            if (value !== undefined) {
                // HERE IS TO PARSE TOML STRING
                if (typeof value === "string") {
                    try {
                        value = toml.parse(value);
                        RED.util.setMessageProperty(msg,node.property,value);
                        send(msg);
                        done();
                    }
                    catch(e) { done(e.message); }
                }
                // HERE IS TO STRINGIFY JSON TO TOML'ish
                else if (typeof value === "object") {
                    if (!Buffer.isBuffer(value)) {
                        try {
                            value = toml.stringify(value, {newline:'\n'});
                            RED.util.setMessageProperty(msg,node.property,value);
                            send(msg);
                            done();
                        }
                        catch(e) {
                            done(RED._("toml.errors.dropped-error"));
                        }
                    }
                    else { node.warn(RED._("toml.errors.dropped-object")); done(); }
                }
                else { node.warn(RED._("toml.errors.dropped")); done(); }
            }
            else { send(msg); done(); } // If no payload - just pass it on.
        });
    }
    RED.nodes.registerType("toml",TOMLNode);
};

Any Idea what the problem could be?

What does `.Error` mean in `import Error from '.Error'`?

Hello.
I've never seen such import declaration: import Error from '.Error';.
Why does it start with a dot?
What behavior should I expect from this notation?
Please, share a link to some article about this declaration.

Thank you,
Ilya.

[Feature] Option to use double quotes for strings

It would be really nice to have an option to use double quotes instead of single quotes for strings.

test("quotes", () => {
  const obj = toml.parse('title = "test"', { joiner: "\n" });
  const out = toml.stringify(obj, { newline: "\n", T: " " });
  expect(out).toEqual('title = "test"');
});
- title = "test"
+ title = 'test'

SyntaxError: Invalid or unexpected token.. es6?

Hi @LongTengDao ,

I am trying to use @ltd/js-tom v1.12.0 with es6 syntax with Nodejs v16.1.0
I am using https://www.npmjs.com/package/esm as the module loader.

I am not using webpack or any other bundler.

My simple test I have two files:

main.js

require = require('esm')(module);
require('./start.js').default.run();

start.js

import toml from '@ltd/j-toml';

const myStart = {
  run: () => {
    console.log('ok');
  }
};

export default myStart;

Then I execute it:

$ node ./main.js

I get this:

... node_modules/@ltd/j-toml/index.js:696
                        const key         = ( ( _.startsWith('\'') ? __LITERAL_KEY_exec : __BARE_KEY_exec )(_) ?? throws(SyntaxError$1(`Bad $
{_.startsWith('\'') ? 'literal string' : 'bare'} key` + where(' at '))) )[0];
                                                                                           ^

SyntaxError: Invalid or unexpected token
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)

I wonder if you can help me? Or know where the problem lays in the npm package.

Simpler `parse()` function

There are a few points of the current API that feel a little odd to me:

  • I don't know why I'm required to pass a TOML version and multiLineJoiner. These could be made optional, I think. Other (but often older) parsers also make these optional or don't even have that option.
  • Passing version as a number is dangerous! 0.1 + 0.2 is not 0.3. Also, how would you represent version 1.1.1 as a number?
  • It would be easier to set individual settings if all settings were an object.

I think the following would be easier to use:

const TOML = require('@ltd/j-toml');

const data = TOML.parse('...', {
  version: '1.0', // could default to '1.0'
  multiLineJoiner: '\n', // could default to '\n'
  useBigInt: true, // already defaults to true
  xOptions: false // already defaults to false (I think?)
});

Most of the time it would be enough to use it like this:

const data = TOML.parse('...');

bug: npm bundle is invalid with version 1.35.0

The top most line in the index.d.ts file of the npm bundle is invalid as of version 1.35.0:

export = exports;

image

Reverting to ~1.33.0 fixes it for now.

I diffed the 2 versions and the reason is you added:

	export class Keys extends RegExp {
	readonly lastIndex :number;
	constructor (keys :ArrayLike<string>);
	readonly test :(this :Keys, key :string) => boolean;
}

See diff here: https://www.diffchecker.com/3Ra291yt

TypeScript doesn't allow mixing export = with other top level exports.

Can't Parse a Stringified example.

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

Section equivalent for arrays?

Is it possible to have something like Section for arrays?

Example scenario:

Code:

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

const parsed = TOML.parse('version = 0.1');
parsed.task = parsed.task || [];
parsed.task.push({ custom: 'task' });

console.log(TOML.stringify(parsed, { newline: '\n' }));

Currently this outputs:

version = 0.1
task = [
	{ custom = 'task' },
]

when I would like it to output:

version = 0.1
[[task]]
custom = 'task'

If I wrap the array creation with Section it throws. If I try use multiline it throws as well. Is there an option here for the parsed.task = [] initialization line?

[feature?] Multiline in stringify

It would be great to be able to set up multiline by default in when stringifying. On properties with strings with \n or \r\n

Actual Behaviour:
In:

title = "Development Page"
description = """
Multi
Line
Test
"""

parse and stringify

const obj = toml.parse(string, { joiner: "\n" });
const out = toml.stringify(obj, { newline: "\n", T: " " });
+
-    title = "Development Page"
+   title = 'Development Page'
-   description = """
-   Multi
-   Line
-   Test
-   """
+  description = "Multi\nLine\nTest\n"

use in browser

need to use toml in browser, so how to build a version for the browser

Maintain "style"

Hi, thanks for the wonderful library.

const doc = `title = "Development Page"
description = """
Multi
Line
Test
"""
`
const obj = toml.parse(doc, { joiner: "\n" });
obj.description = 'Multi\nLine\nTest\n1'
const out = toml.stringify(obj, { newline: "\n", T: " " });

Results in:

title = "Development Page"
description = "Multi\nLine\nTest\n1"

(description is no longer a multi-line string).

Similar applies to numbers (updating adds zeroes). Is there a way to maintain style even after editing? Even if it has to later be added in before converting back to toml.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.