From 69581e4e218f70d689009712b2b5b1e0f12834e7 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 17 Apr 2021 02:08:04 +0700 Subject: [PATCH] Require Node.js 12 and move to ESM --- .github/workflows/main.yml | 3 +-- index.d.ts | 6 ++---- index.js | 6 ++---- index.test-d.ts | 2 +- package.json | 10 ++++++---- readme.md | 2 +- test.js | 2 +- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c1870cf..d36e1a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,10 +12,9 @@ jobs: node-version: - 14 - 12 - - 10 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index ddf9c41..589f253 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,7 +5,7 @@ An object is plain if it's created by either `{}`, `new Object()`, or `Object.cr @example ``` -import isPlainObject = require('is-plain-obj'); +import isPlainObject from 'is-plain-obj'; isPlainObject({foo: 'bar'}); //=> true @@ -24,6 +24,4 @@ isPlainObject(new Unicorn()); //=> false ``` */ -declare function isPlainObject(value: unknown): value is Record; - -export = isPlainObject; +export default function isPlainObject(value: unknown): value is Record; diff --git a/index.js b/index.js index 95079ec..418b079 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,8 @@ -'use strict'; - -module.exports = value => { +export default function isPlainObject(value) { if (Object.prototype.toString.call(value) !== '[object Object]') { return false; } const prototype = Object.getPrototypeOf(value); return prototype === null || prototype === Object.prototype; -}; +} diff --git a/index.test-d.ts b/index.test-d.ts index 096bf05..b6818fc 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectAssignable} from 'tsd'; -import isPlainObject = require('.'); +import isPlainObject from './index.js'; const foo = 'foo'; diff --git a/package.json b/package.json index ad68d6b..31c66c4 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,10 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=10" + "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" @@ -32,8 +34,8 @@ "simple" ], "devDependencies": { - "ava": "^2.4.0", - "tsd": "^0.13.1", - "xo": "^0.33.1" + "ava": "^3.15.0", + "tsd": "^0.14.0", + "xo": "^0.38.2" } } diff --git a/readme.md b/readme.md index a57d776..d63a165 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@ $ npm install is-plain-obj ## Usage ```js -const isPlainObject = require('is-plain-obj'); +import isPlainObject from 'is-plain-obj'; isPlainObject({foo: 'bar'}); //=> true diff --git a/test.js b/test.js index aa94ba7..993e9a8 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,5 @@ import test from 'ava'; -import isPlainObject from '.'; +import isPlainObject from './index.js'; function Foo(x) { this.x = x;