Skip to content

Commit

Permalink
feat: hasOwn support Node.js 14 (#25)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
	- Introduced a new CI workflow for Node.js version 14.
  
- **Improvements**
	- Expanded CI testing to include Node.js version 22.
	- Updated dependency version for `tshy` to 3.0.2.
- Enhanced compatibility for property checks across different Node.js
versions.
	- Added various badges and a contributors section to the README.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Dec 9, 2024
1 parent 2aa95f8 commit 857bdff
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '16, 18, 20'
version: '16, 18, 20, 22'
22 changes: 22 additions & 0 deletions .github/workflows/nodejs-14.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Node.js 14 CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '14'
- run: npm install
- run: node -v
- run: npm test
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# is-type-of

[![NPM version][npm-image]][npm-url]
[![CI](https://github.com/node-modules/is-type-of/actions/workflows/ci.yml/badge.svg)](https://github.com/node-modules/is-type-of/actions/workflows/ci.yml)
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version][node-version-image]][node-version-url]

[npm-image]: https://img.shields.io/npm/v/is-type-of.svg?style=flat-square
[npm-url]: https://npmjs.org/package/is-type-of
[codecov-image]: https://codecov.io/github/node-modules/is-type-of/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/node-modules/is-type-of?branch=master
[snyk-image]: https://snyk.io/test/npm/is-type-of/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/is-type-of
[download-image]: https://img.shields.io/npm/dm/is-type-of.svg?style=flat-square
[download-url]: https://npmjs.org/package/is-type-of
[node-version-image]: https://img.shields.io/node/v/is-type-of.svg?style=flat-square
[node-version-url]: https://nodejs.org/en/download/

Complete type checking for Node

## Features
Expand Down Expand Up @@ -288,3 +306,9 @@ See Also `is.longObject`
## License

[MIT](LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=node-modules/is-type-of)](https://github.com/node-modules/is-type-of/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
"eslint": "^8.54.0",
"eslint-config-egg": "^13.0.0",
"long": "^3.2.0",
"semver": "^5.4.1",
"semver": "^7.6.3",
"ts-expect": "^1.3.0",
"tshy": "^1.0.0",
"tshy": "^3.0.2",
"tshy-after": "^1.0.0",
"typescript": "^5.2.2"
},
Expand Down
6 changes: 5 additions & 1 deletion src/types/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export function isInstanceOf<T extends Class>(val: unknown, Clazz: T): val is In
}

export function hasOwnProperty<T extends object>(obj: T, prop: PropertyKey): obj is T & Record<typeof prop, unknown> {
return Object.hasOwn(obj, prop);
if (Object.hasOwn) {
// Node.js >= 16
return Object.hasOwn(obj, prop);
}
return Object.prototype.hasOwnProperty.call(obj, prop);
}

export function hasOwnPropertyInChain<T extends object>(obj: T, prop: PropertyKey): obj is T & Record<typeof prop, unknown> {
Expand Down

0 comments on commit 857bdff

Please sign in to comment.