diff --git a/README.md b/README.md index 125c77e..14dde74 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,13 @@ include the `jsonSpread.min.js` file from the dist folder ## TypeScript Support -This library includes TypeScript type definitions. You can import and use it in your TypeScript projects: +This library includes TypeScript type definitions. You can use it in your TypeScript projects: ```typescript +// CommonJS style +const jsonSpread = require('json-spread'); + +// OR ES Module style import jsonSpread from 'json-spread'; // Use generics to specify the return type diff --git a/index.d.ts b/index.d.ts index 5b32366..2f14d97 100644 --- a/index.d.ts +++ b/index.d.ts @@ -52,4 +52,7 @@ declare namespace jsonSpread { export const spread: typeof JsonSpread.spread; } -export = jsonSpread; \ No newline at end of file +// Support for CommonJS exports +export = jsonSpread; +// Support for TypeScript usage in global environment +export as namespace jsonSpread; \ No newline at end of file diff --git a/package.json b/package.json index de1cb3e..94bfe1c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "json-spread", "version": "0.3.2", "description": "simple javascript utility to spread nested json or javascript objects", - "main": "index.js", + "main": "dist/jsonSpread.js", "types": "index.d.ts", "scripts": { "test": "mocha",