Skip to content

Commit cf204a3

Browse files
committed
Add esm support and migrate to named export
1 parent c11ae0e commit cf204a3

File tree

9 files changed

+30
-21
lines changed

9 files changed

+30
-21
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ tmp
2727
TODO.md
2828
package-lock.json
2929
browser
30-
index.cjs.js
31-
index.es.js
30+
dist

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ Use [isobject](https://github.com/jonschlinkert/isobject) if you only want to ch
1616

1717
## Usage
1818

19+
with es modules
1920
```js
20-
import isPlainObject from 'is-plain-object';
21+
import { isPlainObject } from 'is-plain-object';
22+
```
23+
24+
or with commonjs
25+
```js
26+
const { isPlainObject } = require('is-plain-object');
2127
```
2228

2329
**true** when created by the `Object` constructor, or Object.create(null).

index.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

is-plain-object.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function isPlainObject(o: any): boolean;

index.js renamed to is-plain-object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function isObject(o) {
99
return Object.prototype.toString.call(o) === '[object Object]';
1010
}
1111

12-
export default function isPlainObject(o) {
12+
export function isPlainObject(o) {
1313
var ctor,prot;
1414

1515
if (isObject(o) === false) return false;

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616
"url": "https://github.com/jonschlinkert/is-plain-object/issues"
1717
},
1818
"license": "MIT",
19-
"main": "index.cjs.js",
20-
"module": "index.es.js",
21-
"types": "index.d.ts",
19+
"main": "dist/is-plain-object.js",
20+
"module": "dist/is-plain-object.mjs",
21+
"types": "is-plain-object.d.ts",
2222
"files": [
23-
"index.d.ts",
24-
"index.es.js",
25-
"index.cjs.js"
23+
"is-plain-object.d.ts",
24+
"dist"
2625
],
26+
"exports": {
27+
".": {
28+
"import": "./dist/is-plain-object.mjs",
29+
"require": "./dist/is-plain-object.js"
30+
},
31+
"./package.json": "./package.json"
32+
},
2733
"engines": {
2834
"node": ">=0.10.0"
2935
},

rollup.config.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
export default {
2-
input: './index.js',
2+
input: './is-plain-object.js',
33
output: [
44
{
55
format: 'iife',
66
file: 'browser/is-plain-object.js',
7-
name: 'isPlainObject',
8-
exports: 'default'
7+
name: 'library',
98
},
109
{
1110
format: 'cjs',
12-
file: 'index.cjs.js',
13-
exports: 'default'
11+
file: 'dist/is-plain-object.js',
1412
},
1513
{
16-
format: 'es',
17-
file: 'index.es.js'
14+
format: 'esm',
15+
file: 'dist/is-plain-object.mjs'
1816
}
1917
]
2018
}

test/browser.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<div id="mocha"></div>
1313
<script>
1414

15+
const { isPlainObject } = library;
16+
1517
var expect = chai.expect;
1618
var iframe,iframeWindow;
1719
var testArea = document.getElementById('mocha');

test/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import assert from 'assert';
9-
import isPlainObject from '../index.js';
9+
import { isPlainObject } from '../is-plain-object.js';
1010

1111
describe('Same-Realm Server Tests', function() {
1212
it('should return `true` if the object is created by the `Object` constructor.', function() {

0 commit comments

Comments
 (0)