Skip to content

Commit

Permalink
feat: drop Node.js v12 support
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Node.js v12 is no longer supported.
  • Loading branch information
kenany committed Nov 23, 2022
1 parent df1c413 commit 5d956eb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12, 14, 16]
node-version: [14, 16, 18]
os: [ubuntu-latest]
steps:
- uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Node.js
uses: actions/[email protected]
with:
node-version: 16
node-version: 18
- name: Update npm
run: |
npm install -g npm
Expand Down
44 changes: 22 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var forEach = require('lodash.foreach');
var isDate = require('lodash.isdate');
var isEmpty = require('lodash.isempty');
var isPlainObject = require('lodash.isplainobject');
var keys = require('lodash.keys');
var strftime = require('strftime');
'use strict';

const isDate = require('lodash.isdate');
const isEmpty = require('lodash.isempty');
const isPlainObject = require('lodash.isplainobject');
const strftime = require('strftime');

/**
* @param {unknown} obj
Expand All @@ -21,7 +21,7 @@ function format(obj) {
*/
function isArrayOfTables(simplePairs) {
return simplePairs.some(function(array) {
var value = array[1];
const value = array[1];
return Array.isArray(value) && isPlainObject(value[0]);
});
}
Expand All @@ -39,7 +39,7 @@ function isObjectArrayOfTables(obj) {
* @returns {boolean}
*/
function isLastObjectArrayOfTables(simplePairs) {
var array = simplePairs[simplePairs.length - 1];
const array = simplePairs[simplePairs.length - 1];
return isObjectArrayOfTables(array);
}

Expand All @@ -65,13 +65,13 @@ module.exports = function(hash, options = {}) {
* @returns {void}
*/
function visit(hash, prefix) {
var nestedPairs = [];
var simplePairs = [];
const nestedPairs = [];
const simplePairs = [];

var indentStr = '';
let indentStr = '';

forEach(keys(hash).sort(), function(key) {
var value = hash[key];
Object.keys(hash).sort().forEach((key) => {
const value = hash[key];
(isPlainObject(value) ? nestedPairs : simplePairs).push([key, value]);
});

Expand All @@ -81,18 +81,18 @@ module.exports = function(hash, options = {}) {
indentStr = ''.padStart(options.indent, ' ');
}

forEach(simplePairs, function(array) {
var key = array[0];
var value = array[1];
simplePairs.forEach((array) => {
const key = array[0];
const value = array[1];

if (isObjectArrayOfTables(array)) {
if (simplePairs.indexOf(array) > 0 && options.newlineAfterSection) {
var lastObj = simplePairs[simplePairs.indexOf(array) - 1];
const lastObj = simplePairs[simplePairs.indexOf(array) - 1];
if (!isObjectArrayOfTables(lastObj)) {
toml += '\n';
}
}
forEach(value, function(obj) {
value.forEach((obj) => {
if (!isEmpty(prefix)) {
toml += '[[' + prefix + '.' + key + ']]\n';
}
Expand All @@ -112,9 +112,9 @@ module.exports = function(hash, options = {}) {
toml += '\n';
}

forEach(nestedPairs, function(array) {
var key = array[0];
var value = array[1];
nestedPairs.forEach((array) => {
const key = array[0];
const value = array[1];

visit(
value,
Expand All @@ -125,7 +125,7 @@ module.exports = function(hash, options = {}) {
});
}

var toml = '';
let toml = '';

visit(hash, '');

Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,25 @@
"test": "test"
},
"engines": {
"node": "12 || 14 || >=16"
"node": "14 || 16 || >=18"
},
"scripts": {
"lint": "eslint .",
"release": "semantic-release",
"test": "nyc --reporter html --reporter text tape test/index.js"
},
"dependencies": {
"lodash.foreach": "^4.5.0",
"lodash.isdate": "^4.0.1",
"lodash.isempty": "^4.4.0",
"lodash.isplainobject": "^4.0.6",
"lodash.keys": "^4.2.0",
"strftime": "^0.10.1"
},
"devDependencies": {
"@kenan/eslint-config": "^9.0.4",
"@kenan/eslint-config": "^10.0.1",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"conventional-changelog-conventionalcommits": "^5.0.0",
"eslint": "^7.32.0",
"eslint": "^8.28.0",
"nyc": "^15.1.0",
"semantic-release": "^19.0.5",
"tape": "^5.6.1"
Expand Down
38 changes: 38 additions & 0 deletions test/key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const test = require('tape');

const json2toml = require('../');

test('key > case sensitive', (t) => {
t.plan(1);

const obj = {
sectioN: 'NN',
section: {
name: 'lower',
NAME: 'upper',
Name: 'capitalized'
},
Section: {
name: 'different section!!',
μ: 'greek small letter mu',
Μ: 'greek capital letter MU',
M: 'latin letter M'
}
};
t.equal(
json2toml(obj),
`sectioN = "NN"
[section]
name = "lower"
NAME = "upper"
Name = "capitalized"
[Section]
name = "different section!!"
"μ" = "greek small letter mu"
"Μ" = "greek capital letter MU"
M = "latin letter M"
`
);
});

0 comments on commit 5d956eb

Please sign in to comment.