Skip to content

Commit

Permalink
refactor: setup project for TypeScript (#7)
Browse files Browse the repository at this point in the history
docs: add jsdoc

chore: add prettier

chore: add node 16 to CI

feat!: no default export

BREAKING CHANGE: When using this project you will need to use a named import:
`import { isAnyArray } from 'is-any-array'`

chore: remove useless dependencies
  • Loading branch information
lpatiny committed Oct 11, 2021
1 parent c5224d9 commit 21e47a0
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 36 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintrc.yml
@@ -1,3 +1,3 @@
extends: eslint-config-cheminfo
extends: cheminfo-typescript
parserOptions:
sourceType: module
6 changes: 5 additions & 1 deletion .github/workflows/nodejs.yml
Expand Up @@ -20,11 +20,15 @@ jobs:
run: npm install
- name: Run ESLint
run: npm run eslint
- name: Run Prettier
run: npm run prettier
- name: Check types
run: npm run check-types
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 15.x]
node-version: [12.x, 14.x, 16.x]
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ logs
npm-debug.log*
coverage
lib
lib-esm
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -13,7 +13,7 @@ Check if a value is any kind of array.
## Example

```js
const isAnyArray = require('is-any-array');
const {isAnyArray} = require('is-any-array');

isAnyArray(1); // false
isAnyArray('ab'); // false
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'node',
};
41 changes: 21 additions & 20 deletions package.json
Expand Up @@ -2,17 +2,26 @@
"name": "is-any-array",
"version": "1.0.1",
"description": "Check if a value is any kind of array",
"main": "lib/index.js",
"module": "src/index.js",
"main": "./lib/index.js",
"module": "./lib-esm/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib",
"lib-esm",
"src"
],
"scripts": {
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"eslint": "eslint src",
"eslint-fix": "npm run eslint -- --fix",
"prepack": "rollup -c",
"test": "npm run test-coverage && npm run eslint",
"prepack": "npm run tsc",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc --project tsconfig.cjs.json",
"tsc-esm": "tsc --project tsconfig.esm.json",
"test": "npm run test-coverage && npm run eslint && npm run check-types",
"test-coverage": "jest --coverage",
"test-only": "jest"
},
Expand All @@ -27,22 +36,14 @@
"url": "https://github.com/cheminfo-js/is-any-array/issues"
},
"homepage": "https://github.com/cheminfo-js/is-any-array#readme",
"jest": {
"testEnvironment": "node"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.14.5",
"cheminfo-build": "^1.1.11",
"cheminfo-tools": "^1.23.3",
"codecov": "^3.8.2",
"eslint": "^7.29.0",
"eslint-config-cheminfo": "^5.2.4",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.6",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.2",
"rollup": "^2.52.4"
"@types/jest": "^27.0.2",
"eslint": "^7.32.0",
"eslint-config-cheminfo-typescript": "^8.0.9",
"jest": "^27.2.5",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3"
}
}
8 changes: 0 additions & 8 deletions rollup.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/__tests__/test.js
@@ -1,4 +1,4 @@
import isAnyArray from '..';
import { isAnyArray } from '..';

test('isArray', () => {
expect(isAnyArray(1)).toBe(false);
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
@@ -1,5 +1,10 @@
const toString = Object.prototype.toString;

export default function isAnyArray(object) {
/**
* Checks if an object is an instance of an Array (array or typed array)
* @param {any} object to check
* @returns {boolean}
*/
export function isAnyArray(object) {
return toString.call(object).endsWith('Array]');
}
9 changes: 9 additions & 0 deletions tsconfig.cjs.json
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"declarationMap": true
},
"exclude": ["./src/**/__tests__"]
}
7 changes: 7 additions & 0 deletions tsconfig.esm.json
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.cjs.json",
"compilerOptions": {
"module": "es2020",
"outDir": "lib-esm"
}
}
12 changes: 12 additions & 0 deletions tsconfig.json
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"moduleResolution": "node",
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2020"
},
"include": ["./src/**/*"]
}

0 comments on commit 21e47a0

Please sign in to comment.