Skip to content

Commit

Permalink
Breaking: Use a named export
Browse files Browse the repository at this point in the history
Increases compatibility a lot across CommonJS / ESM / TypeScript

Also makes it easier to export other things in the future
  • Loading branch information
Pelle Wessman committed Oct 30, 2022
1 parent 4fe7055 commit 9e73060
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/dist
/index.d.ts
/index.js
/src
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ SDK for the Socket API client, generated by `api`.
npm install @socketsecurity/sdk
```

### ESM / TypeScript

```javascript
const client = require('@socketsecurity/sdk').auth('yourApiKeyHere')
import { socketSdk } from '@socketsecurity/sdk'

const client = socketSdk.auth('yourApiKeyHere')

const res = await client.getIssuesByNPMPackage({
package: '@socketsecurity/eslint-config',
version: '1.0.0'
})
```

### CommonJS

```javascript
const { socketSdk } = require('@socketsecurity/sdk')
```

## See also

* [Socket API Reference](https://docs.socket.dev/reference)
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import socketSdk from './dist'

export { socketSdk }
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const socketSdk = require('./dist').default;

module.exports = { socketSdk }
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist/**/*.js",
"dist/**/*.d.ts",
"dist/**/*.json"
"dist/**/*.js",
"dist/**/*.json",
"index.d.ts",
"index.js"
],
"dependencies": {
"api": "^5.0.0-beta.3",
Expand Down

0 comments on commit 9e73060

Please sign in to comment.