Skip to content

Commit

Permalink
Add esm support and migrate to named export
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Sep 9, 2020
1 parent c11ae0e commit cf204a3
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 21 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ tmp
TODO.md
package-lock.json
browser
index.cjs.js
index.es.js
dist
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ Use [isobject](https://github.com/jonschlinkert/isobject) if you only want to ch

## Usage

with es modules
```js
import isPlainObject from 'is-plain-object';
import { isPlainObject } from 'is-plain-object';
```

or with commonjs
```js
const { isPlainObject } = require('is-plain-object');
```

**true** when created by the `Object` constructor, or Object.create(null).
Expand Down
3 changes: 0 additions & 3 deletions index.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions is-plain-object.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function isPlainObject(o: any): boolean;
2 changes: 1 addition & 1 deletion index.js → is-plain-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function isObject(o) {
return Object.prototype.toString.call(o) === '[object Object]';
}

export default function isPlainObject(o) {
export function isPlainObject(o) {
var ctor,prot;

if (isObject(o) === false) return false;
Expand Down
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
"url": "https://github.com/jonschlinkert/is-plain-object/issues"
},
"license": "MIT",
"main": "index.cjs.js",
"module": "index.es.js",
"types": "index.d.ts",
"main": "dist/is-plain-object.js",
"module": "dist/is-plain-object.mjs",
"types": "is-plain-object.d.ts",
"files": [
"index.d.ts",
"index.es.js",
"index.cjs.js"
"is-plain-object.d.ts",
"dist"
],
"exports": {
".": {
"import": "./dist/is-plain-object.mjs",
"require": "./dist/is-plain-object.js"
},
"./package.json": "./package.json"
},
"engines": {
"node": ">=0.10.0"
},
Expand Down
12 changes: 5 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
export default {
input: './index.js',
input: './is-plain-object.js',
output: [
{
format: 'iife',
file: 'browser/is-plain-object.js',
name: 'isPlainObject',
exports: 'default'
name: 'library',
},
{
format: 'cjs',
file: 'index.cjs.js',
exports: 'default'
file: 'dist/is-plain-object.js',
},
{
format: 'es',
file: 'index.es.js'
format: 'esm',
file: 'dist/is-plain-object.mjs'
}
]
}
2 changes: 2 additions & 0 deletions test/browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<div id="mocha"></div>
<script>

const { isPlainObject } = library;

var expect = chai.expect;
var iframe,iframeWindow;
var testArea = document.getElementById('mocha');
Expand Down
2 changes: 1 addition & 1 deletion test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

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

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

0 comments on commit cf204a3

Please sign in to comment.