Skip to content

Commit

Permalink
Require Node.js 14
Browse files Browse the repository at this point in the history
Fixes #77
  • Loading branch information
sindresorhus committed Jan 16, 2023
1 parent e6ef8e2 commit 5f5a302
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 18
- 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
11 changes: 4 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isRegexp from 'is-regexp';
import isObject from 'is-obj';
import getOwnEnumPropSymbols from 'get-own-enumerable-property-symbols';
import getOwnEnumerableKeys from 'get-own-enumerable-keys';

export default function stringifyObject(input, options, pad) {
const seen = [];
Expand Down Expand Up @@ -89,10 +89,7 @@ export default function stringifyObject(input, options, pad) {
}

if (isObject(input)) {
let objectKeys = [
...Object.keys(input),
...getOwnEnumPropSymbols.default(input),
];
let objectKeys = getOwnEnumerableKeys(input);

if (options.filter) {
// eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
Expand All @@ -105,8 +102,8 @@ export default function stringifyObject(input, options, pad) {

seen.push(input);

const returnValue = '{' + tokens.newline + objectKeys.map((element, i) => {
const eol = objectKeys.length - 1 === i ? tokens.newline : ',' + tokens.newlineOrSpace;
const returnValue = '{' + tokens.newline + objectKeys.map((element, index) => {
const eol = objectKeys.length - 1 === index ? tokens.newline : ',' + tokens.newlineOrSpace;
const isSymbol = typeof element === 'symbol';
const isClassic = !isSymbol && /^[a-z$_][$\w]*$/i.test(element);
const key = isSymbol || isClassic ? element : stringify(element, options);
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Stringify an object/array like JSON.stringify just without all the double-quotes",
"license": "BSD-2-Clause",
"repository": "yeoman/stringify-object",
"funding": "https://github.com/yeoman/stringify-object?sponsor=1",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
Expand All @@ -12,7 +13,7 @@
"type": "module",
"exports": "./index.js",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=14.16"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -31,13 +32,13 @@
"json"
],
"dependencies": {
"get-own-enumerable-property-symbols": "^3.0.2",
"get-own-enumerable-keys": "^1.0.0",
"is-obj": "^3.0.0",
"is-regexp": "^3.0.0"
"is-regexp": "^3.1.0"
},
"devDependencies": {
"ava": "^3.15.0",
"xo": "^0.44.0"
"ava": "^5.1.1",
"xo": "^0.53.1"
},
"xo": {
"ignores": [
Expand Down
16 changes: 2 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ It also handles circular references and lets you specify quote type.

## Install

```
$ npm install stringify-object
```sh
npm install stringify-object
```

## Usage
Expand Down Expand Up @@ -156,15 +156,3 @@ console.log(pretty);
```

As you can see, `arr` was printed as a one-liner because its string was shorter than 12 characters.

---

<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-stringify-object?utm_source=npm-stringify-object&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ test('allows an object to be transformed', t => {
};

const actual = stringifyObject(object, {
transform: (object, prop, result) => {
transform(object, prop, result) {
if (prop === 'val') {
return String(object[prop] + 1);
}
Expand Down

0 comments on commit 5f5a302

Please sign in to comment.