Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: BREAKING_CHANGE rewrite in typescript #19

Merged
merged 7 commits into from Jul 28, 2023
Merged

feat: BREAKING_CHANGE rewrite in typescript #19

merged 7 commits into from Jul 28, 2023

Conversation

popomore
Copy link
Member

This Pull Request is rewriting code in Typescript

New Feature

ES Module Import

use default export

import is from 'is-type-of';
is.string('');

compatible with commonjs

const is = require('is-type-of');
const { string } = require('is-type-of');
is.string('');
string('');

use checking method directly, using isString('') is better than string('')

import { isString } from 'is-type-of';
isString('');

Type Guard

Accroding to https://www.typescriptlang.org/docs/handbook/2/narrowing.html, support type checking

const val: unknown = '1';
val.includes('1');    // error: val is of type 'unknown' 
if (isString(val)) {
  val.includes('1');  // success
}

New API

  • isNullable
  • isInteger
  • isInteger32
  • isAsyncGeneratorFunction
  • isPromiseLike

Breaking Change

  • drop Node 14
  • Don't depend on core-util-is, isstream

@socket-security
Copy link

socket-security bot commented Jul 27, 2023

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
typescript 5.1.6 None +0 40.1 MB typescript-bot
eslint 8.45.0 eval, filesystem, environment +46 8.8 MB eslintbot

🚮 Removed packages: tsd@0.28.1

@popomore popomore force-pushed the refactor-ts branch 2 times, most recently from 49e3c5f to 20bd302 Compare July 27, 2023 17:03
@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

Merging #19 (8c506bb) into master (695bcaf) will not change coverage.
Report is 1 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##            master       #19    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            1         7     +6     
  Lines          125       769   +644     
  Branches        23        81    +58     
==========================================
+ Hits           125       769   +644     
Files Changed Coverage Δ
src/index.ts 100.00% <100.00%> (ø)
src/is.ts 100.00% <100.00%> (ø)
src/types/external.ts 100.00% <100.00%> (ø)
src/types/node.ts 100.00% <100.00%> (ø)
src/types/primitive.ts 100.00% <100.00%> (ø)
src/types/std.ts 100.00% <100.00%> (ø)
src/types/util.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

package.json Outdated
"typescript": "^5.1.6"
},
"dependencies": {
"@types/long": "^5.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependencies 不需要加

type Primitive = string | number | bigint | boolean | symbol | null | undefined;
type Nullable = null | undefined;

export function isString(val?: unknown): val is string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val is string 学习了

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

断言的时候用 asserts 也很好用,类型确定 https://blog.logrocket.com/assertion-functions-typescript/

@popomore popomore changed the title WIP: feat: BREAKING_CHANGE rewrite in typescript feat: BREAKING_CHANGE rewrite in typescript Jul 28, 2023
@popomore
Copy link
Member Author

文档也写完了

@fengmk2 fengmk2 merged commit 58b5703 into master Jul 28, 2023
7 checks passed
@fengmk2 fengmk2 deleted the refactor-ts branch July 28, 2023 14:50
@fengmk2
Copy link
Member

fengmk2 commented Jul 28, 2023

2.0.0 released

fengmk2 pushed a commit that referenced this pull request Jul 28, 2023
[skip ci]

## [2.0.0](v1.4.0...v2.0.0) (2023-07-28)

### ⚠ BREAKING CHANGES

* drop Node.js <= 14

### Features

* rewrite in typescript ([#19](#19)) ([58b5703](58b5703))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants