smol-toml 1.5.0 → 1.5.1

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  [![TOML 1.0.0](https://img.shields.io/badge/TOML-1.0.0-9c4221?style=flat-square)](https://toml.io/en/v1.0.0)
3
3
  [![License](https://img.shields.io/github/license/squirrelchat/smol-toml.svg?style=flat-square)](https://github.com/squirrelchat/smol-toml/blob/mistress/LICENSE)
4
4
  [![npm](https://img.shields.io/npm/v/smol-toml?style=flat-square)](https://npm.im/smol-toml)
5
- [![Build](https://img.shields.io/github/actions/workflow/status/squirrelchat/smol-toml/build.yml?style=flat-square&logo=github)](https://github.com/squirrelchat/smol-toml/actions/workflows/build.yml)
5
+ [![Build](https://img.shields.io/github/actions/workflow/status/squirrelchat/smol-toml/build.yaml?style=flat-square&logo=github)](https://github.com/squirrelchat/smol-toml/actions/workflows/build.yaml)
6
6
 
7
7
  [![GitHub Sponsors](https://img.shields.io/badge/GitHub%20Sponsors-support%20me-EA4AAA?style=flat-square)](https://github.com/sponsors/cyyynthia)
8
8
  [![Weekly downloads](https://img.shields.io/npm/dw/smol-toml?style=flat-square)](https://npm.im/smol-toml)
package/dist/index.cjs CHANGED
@@ -820,10 +820,9 @@ function stringifyArrayTable(array, key, depth, numberAsFloat) {
820
820
  }
821
821
  let res = "";
822
822
  for (let i = 0; i < array.length; i++) {
823
- res += `[[${key}]]
823
+ res += `${res && "\n"}[[${key}]]
824
824
  `;
825
825
  res += stringifyTable(0, array[i], key, depth, numberAsFloat);
826
- res += "\n";
827
826
  }
828
827
  return res;
829
828
  }
@@ -847,8 +846,7 @@ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
847
846
  } else if (type === "object") {
848
847
  let tblKey = prefix ? `${prefix}.${key}` : key;
849
848
  let table = stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
850
- if (table)
851
- tables += table + "\n";
849
+ tables += (tables && "\n") + table;
852
850
  } else {
853
851
  preamble += key;
854
852
  preamble += " = ";
@@ -867,7 +865,10 @@ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
867
865
  if (extendedTypeOf(obj) !== "object") {
868
866
  throw new TypeError("stringify can only be called with an object");
869
867
  }
870
- return stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
868
+ let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
869
+ if (str[str.length - 1] !== "\n")
870
+ return str + "\n";
871
+ return str;
871
872
  }
872
873
 
873
874
  // dist/index.js
package/dist/stringify.js CHANGED
@@ -115,9 +115,8 @@ function stringifyArrayTable(array, key, depth, numberAsFloat) {
115
115
  }
116
116
  let res = '';
117
117
  for (let i = 0; i < array.length; i++) {
118
- res += `[[${key}]]\n`;
118
+ res += `${res && '\n'}[[${key}]]\n`;
119
119
  res += stringifyTable(0, array[i], key, depth, numberAsFloat);
120
- res += '\n';
121
120
  }
122
121
  return res;
123
122
  }
@@ -142,8 +141,7 @@ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
142
141
  else if (type === 'object') {
143
142
  let tblKey = prefix ? `${prefix}.${key}` : key;
144
143
  let table = stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
145
- if (table)
146
- tables += table + '\n';
144
+ tables += (tables && '\n') + table;
147
145
  }
148
146
  else {
149
147
  preamble += key;
@@ -163,5 +161,8 @@ export function stringify(obj, { maxDepth = 1000, numbersAsFloat = false } = {})
163
161
  if (extendedTypeOf(obj) !== 'object') {
164
162
  throw new TypeError('stringify can only be called with an object');
165
163
  }
166
- return stringifyTable(0, obj, '', maxDepth, numbersAsFloat);
164
+ let str = stringifyTable(0, obj, '', maxDepth, numbersAsFloat);
165
+ if (str[str.length - 1] !== '\n')
166
+ return str + '\n';
167
+ return str;
167
168
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "smol-toml",
3
3
  "license": "BSD-3-Clause",
4
- "version": "1.5.0",
4
+ "version": "1.5.1",
5
5
  "description": "A small, fast, and correct TOML parser/serializer",
6
6
  "author": "Cynthia <cyyynthia@borkenware.com>",
7
7
  "repository": "github:squirrelchat/smol-toml",