Skip to content

Commit

Permalink
feat: use tshy to build and support ESM and CommonJS both (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Nov 25, 2023
1 parent 2d186cc commit 3688cd6
Show file tree
Hide file tree
Showing 23 changed files with 186 additions and 167 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Expand Up @@ -7,12 +7,10 @@ on:
pull_request:
branches: [ master ]

workflow_dispatch: {}

jobs:
Job:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-test.yml@v1
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '16, 18, 20'
2 changes: 0 additions & 2 deletions .github/workflows/codeql.yml
Expand Up @@ -5,8 +5,6 @@ on:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: "15 23 * * 3"

jobs:
analyze:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
release:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
uses: node-modules/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -15,3 +15,4 @@ npm-debug.log
node_modules
.nyc_output
dist
.tshy
77 changes: 77 additions & 0 deletions CHANGELOG.md
Expand Up @@ -32,3 +32,80 @@
### Features

* add d.ts support ([#17](https://github.com/node-modules/is-type-of/issues/17)) ([edcedcc](https://github.com/node-modules/is-type-of/commit/edcedcc70af64c054cc834e5dd2ed79edd4692ff))

---


1.2.1 / 2018-09-22
==================

**fixes**
* [[`1468e4e`](http://github.com/node-modules/is-type-of/commit/1468e4e2d2a1221ff25187f430e5546db2fadacc)] - fix: hotfix is-class bug (#10) (fengmk2 <<fengmk2@gmail.com>>)

**others**
* [[`32aab2b`](http://github.com/node-modules/is-type-of/commit/32aab2b5431e76529f2cf9ddf1d112b99ed05394)] - chore: Improve some functions (#8) (Runrioter Wung <<runrioter@gmail.com>>)

1.2.0 / 2017-08-10
==================

* feat: Add async function test function. (#6)

1.1.0 / 2017-07-19
==================

* deps: upgrade is-class@0.0.4
* feat: is.array() use Array.isArray() directly
* feat: improve is.error performance
* feat: improve is.regExp performance
* test: support coverage
* feat: imrpove is.date performance (#4)

1.0.0 / 2015-11-09
==================

* deps: update all dependencies
* detect class

0.3.1 / 2014-06-20
==================

* add is.finite()

0.3.0 / 2014-05-10
==================

* split Long from long
* fix history

0.2.1 / 2014-04-22
==================

* bump deps version
* Merge pull request #1 from node-modules/support-long-module
* is.long() support long module
* refactor

0.2.0 / 2014-04-07
==================

* add readme for isstream
* add isStream
* add travis-yml

0.1.0 / 2014-04-03
==================

* add isNaN

0.0.2 / 2014-04-01
==================

* add is.int32

0.0.1 / 2014-03-12
==================

* add readme
* add test, add number type checker
* add core-util-is and generator promise
* Initial commit
74 changes: 0 additions & 74 deletions History.md

This file was deleted.

7 changes: 3 additions & 4 deletions benchmark/is.date.js → benchmark/is.date.cjs
@@ -1,16 +1,15 @@
'use strict';

const path = require('path');
const fs = require('fs');
const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');
const t = require('core-util-is');
const is = require('..');
const is = require('is-type-of');
// console.log(require.resolve('is-type-of'));

const nowDate = new Date();
const nowNumber = Date.now();
const shortString = '一点点点中文abc';
const longString = fs.readFileSync(path.join(__dirname, '../index.js'), 'utf8');
const longString = fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8');
const smallBuffer = Buffer.alloc(100);
const bigBuffer = Buffer.alloc(1024 * 1024);

Expand Down
4 changes: 1 addition & 3 deletions benchmark/is.error.js → benchmark/is.error.cjs
@@ -1,11 +1,9 @@
'use strict';

const path = require('path');
const fs = require('fs');
const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');
const t = require('core-util-is');
const is = require('..');
const is = require('is-type-of');

const nowDate = new Date();
const nowNumber = Date.now();
Expand Down
4 changes: 1 addition & 3 deletions benchmark/is.regexp.js → benchmark/is.regexp.cjs
@@ -1,11 +1,9 @@
'use strict';

const path = require('path');
const fs = require('fs');
const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');
const t = require('core-util-is');
const is = require('..');
const is = require('is-type-of');

const nowDate = new Date();
const nowNumber = Date.now();
Expand Down
48 changes: 34 additions & 14 deletions package.json
Expand Up @@ -2,18 +2,34 @@
"name": "is-type-of",
"version": "2.0.1",
"description": "complete type checking for node",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"type": "module",
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"files": [
"dist"
"dist",
"src"
],
"scripts": {
"prepublishOnly": "npm run tsc:clean && npm run tsc:prod",
"tsc": "tsc -b ./tsconfig.json",
"tsc:prod": "tsc -b ./tsconfig.prod.json",
"tsc:clean": "tsc -b --clean",
"prepublishOnly": "tshy && tshy-after",
"test": "egg-bin test",
"ci": "npm run lint && egg-bin cov",
"ci": "npm run lint && egg-bin cov && npm run prepublishOnly",
"lint": "eslint . --ext .ts"
},
"repository": {
Expand All @@ -38,15 +54,19 @@
"devDependencies": {
"@eggjs/tsconfig": "^1.3.3",
"@types/mocha": "^10.0.1",
"@types/node": "^18.16.3",
"@types/node": "^20.6.1",
"beautify-benchmark": "^0.2.4",
"benchmark": "^2.1.4",
"egg-bin": "^6.4.0",
"eslint": "^8.45.0",
"eslint-config-egg": "^12.2.1",
"core-util-is": "^1.0.3",
"egg-bin": "^6.5.2",
"eslint": "^8.49.0",
"eslint-config-egg": "^13.0.0",
"long": "^3.2.0",
"semver": "^5.4.1",
"ts-expect": "^1.3.0",
"typescript": "^5.1.6"
}
"tshy": "^1.0.0",
"tshy-after": "^1.0.0",
"typescript": "^5.2.2"
},
"types": "./dist/commonjs/index.d.ts"
}
18 changes: 9 additions & 9 deletions src/index.ts
@@ -1,12 +1,12 @@
import { is } from './is';
import { isNull, isUndefined, isNaN } from './types/primitive';
import { isClass, isFunction } from './types/std';

export * from './types/primitive';
export * from './types/std';
export * from './types/node';
export * from './types/external';
export { isInstanceOf } from './types/util';
import { is } from './is.js';
import { isNull, isUndefined, isNaN } from './types/primitive.js';
import { isClass, isFunction } from './types/std.js';

export * from './types/primitive.js';
export * from './types/std.js';
export * from './types/node.js';
export * from './types/external.js';
export { isInstanceOf } from './types/util.js';

export default is;

Expand Down
8 changes: 4 additions & 4 deletions src/is.ts
Expand Up @@ -15,7 +15,7 @@ import {
isLong,
isDouble,
isSafeInteger,
} from './types/primitive';
} from './types/primitive.js';
import {
isArray,
isFunction,
Expand All @@ -30,15 +30,15 @@ import {
isObject,
isGenerator,
isPromise,
} from './types/std';
} from './types/std.js';
import {
isBuffer,
isStream,
isReadable,
isWritable,
isDuplex,
} from './types/node';
import { isLongObject } from './types/external';
} from './types/node.js';
import { isLongObject } from './types/external.js';

export const is = {
// Primitive
Expand Down
6 changes: 3 additions & 3 deletions src/types/external.ts
@@ -1,6 +1,6 @@
import { isNumber } from './primitive';
import { isObject } from './std';
import { hasOwnProperty } from './util';
import { isNumber } from './primitive.js';
import { isObject } from './std.js';
import { hasOwnProperty } from './util.js';

interface LongObject {
high: number;
Expand Down
2 changes: 1 addition & 1 deletion src/types/node.ts
@@ -1,6 +1,6 @@
import { Buffer } from 'node:buffer';
import { Duplex, Readable, Stream, Writable } from 'node:stream';
import { hasOwnPropertyInChain, isInstanceOf } from './util';
import { hasOwnPropertyInChain, isInstanceOf } from './util.js';

/**
* returns true if val is buffer
Expand Down
4 changes: 2 additions & 2 deletions src/types/std.ts
@@ -1,8 +1,8 @@
// Javascript Standard Object

import { types, debuglog } from 'node:util';
import { hasOwnProperty, isInstanceOf } from './util';
import type { Class } from './util';
import { hasOwnProperty, isInstanceOf } from './util.js';
import type { Class } from './util.js';

const debug = debuglog('is-type-of:std');

Expand Down

0 comments on commit 3688cd6

Please sign in to comment.