smol-toml 1.5.0 → 1.5.2

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
  }
@@ -843,12 +842,10 @@ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
843
842
  }
844
843
  let key = BARE_KEY.test(k) ? k : formatString(k);
845
844
  if (type === "array" && isArrayOfTables(obj[k])) {
846
- tables += stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
845
+ tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
847
846
  } else if (type === "object") {
848
847
  let tblKey = prefix ? `${prefix}.${key}` : key;
849
- let table = stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
850
- if (table)
851
- tables += table + "\n";
848
+ tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
852
849
  } else {
853
850
  preamble += key;
854
851
  preamble += " = ";
@@ -867,7 +864,10 @@ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
867
864
  if (extendedTypeOf(obj) !== "object") {
868
865
  throw new TypeError("stringify can only be called with an object");
869
866
  }
870
- return stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
867
+ let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
868
+ if (str[str.length - 1] !== "\n")
869
+ return str + "\n";
870
+ return str;
871
871
  }
872
872
 
873
873
  // 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
  }
@@ -137,13 +136,11 @@ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
137
136
  }
138
137
  let key = BARE_KEY.test(k) ? k : formatString(k);
139
138
  if (type === 'array' && isArrayOfTables(obj[k])) {
140
- tables += stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
139
+ tables += (tables && '\n') + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
141
140
  }
142
141
  else if (type === 'object') {
143
142
  let tblKey = prefix ? `${prefix}.${key}` : key;
144
- let table = stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
145
- if (table)
146
- tables += table + '\n';
143
+ tables += (tables && '\n') + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
147
144
  }
148
145
  else {
149
146
  preamble += key;
@@ -163,5 +160,8 @@ export function stringify(obj, { maxDepth = 1000, numbersAsFloat = false } = {})
163
160
  if (extendedTypeOf(obj) !== 'object') {
164
161
  throw new TypeError('stringify can only be called with an object');
165
162
  }
166
- return stringifyTable(0, obj, '', maxDepth, numbersAsFloat);
163
+ let str = stringifyTable(0, obj, '', maxDepth, numbersAsFloat);
164
+ if (str[str.length - 1] !== '\n')
165
+ return str + '\n';
166
+ return str;
167
167
  }
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.2",
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",