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

Add date package with isValidDate #16

Merged
merged 3 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: 16.14.2
Copy link
Owner Author

Choose a reason for hiding this comment

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

yarnpkg/berry#4778

node version issue로 인해 CI에서의 version을 pin합니다.


- name: Lint
run: |
Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: 16.14.2

- name: Test with coverage
run: |
Expand All @@ -42,7 +42,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: 16.14.2

- name: Check is publishable versions
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: 16.14.2
registry-url: 'https://registry.npmjs.org'

- name: Publish packages
Expand Down
19 changes: 19 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"url": "git+https://github.com/kanziw/kanziwjs.git",
"directory": "packages/auth"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/kanziw/kanziwjs/tree/main/packages/auth#readme",
"keywords": [
"auth",
Expand Down
3 changes: 3 additions & 0 deletions packages/cipher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"url": "git+https://github.com/kanziw/kanziwjs.git",
"directory": "packages/cipher"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/kanziw/kanziwjs/tree/main/packages/cipher#readme",
"keywords": [
"cipher",
Expand Down
5 changes: 4 additions & 1 deletion packages/crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "@kanziw/crypto",
"version": "0.0.1",
"version": "0.1.0",
"description": "Authc & Authz Helper",
"repository": {
"type": "git",
"url": "git+https://github.com/kanziw/kanziwjs.git",
"directory": "packages/crypto"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/kanziw/kanziwjs/tree/main/packages/crypto#readme",
"keywords": [
"crypto",
Expand Down
4 changes: 3 additions & 1 deletion packages/crypto/src/sha256.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import crypto from 'crypto'

export const sha256 = (str: string) => crypto.createHash('sha256').update(str).digest()
export const sha256 = (str: string): Buffer => (
crypto.createHash('sha256').update(str).digest()
)
3 changes: 3 additions & 0 deletions packages/date/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/
**/__tests__/
tsconfig.json
16 changes: 16 additions & 0 deletions packages/date/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @kanziwdate/

[![npm version](https://img.shields.io/npm/v/@kanziw/date)](https://www.npmjs.com/package/@kanziw/date)
[![license](https://img.shields.io/npm/l/@kanziw/date)](https://www.npmjs.com/package/@kanziw/date)
[![npm downloads](https://img.shields.io/npm/dt/@kanziw/date)](https://www.npmjs.com/package/@kanziw/date)

## isValidDate

Validate is date object valid

```ts
import { isValidDate } from '@kanziw/date'

isValidDate(new Date()) // true
isValidDate(new Date(NaN)) // false
```
41 changes: 41 additions & 0 deletions packages/date/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@kanziw/date",
"version": "0.1.0",
"description": "A collection of utility libraries about date",
"repository": {
"type": "git",
"url": "git+https://github.com/kanziw/kanziwjs.git",
"directory": "packages/date"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/kanziw/kanziwjs/tree/main/packages/date#readme",
"keywords": [
"date",
"kanziw",
"isValidDate"
],
"author": {
"name": "Jiwoong Jung",
"email": "kanziwoong@gmail.com"
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"packageManager": "yarn@3.2.0",
"scripts": {
"lint": "yarn workspace kanziwjs eslint packages/date",
"test": "yarn workspace kanziwjs test packages/date",
"clean": "rimraf lib",
"build": "yarn clean && yarn tsc",
"publish": "yarn build && yarn publish-if-not-published"
},
"devDependencies": {
"@types/jest": "^27.5.0",
"@types/node": "^17.0.25",
"publish-if-not-published": "^3.1.2",
"rimraf": "^3.0.2",
"typescript": "^4.6.3"
},
"license": "MIT"
}
17 changes: 17 additions & 0 deletions packages/date/src/__tests__/isValidDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { isValidDate } from '../isValidDate'

describe('isValidDate', () => {
test.each([
[new Date(), true],
[new Date(0), true],
[new Date(-8640000000000000), true],
[new Date(8640000000000000), true],
[new Date(-8640000000000000 - 1), false],
[new Date(8640000000000000 + 1), false],
[new Date(''), false],
[new Date(NaN), false],
[new Date(Number.MAX_SAFE_INTEGER + 1), false],
])('isValidDate(%p) === %p', (date, expected) => {
expect(isValidDate(date)).toBe(expected)
})
})
1 change: 1 addition & 0 deletions packages/date/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './isValidDate'
3 changes: 3 additions & 0 deletions packages/date/src/isValidDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const isValidDate = (d: Date): boolean => (
d instanceof Date && !isNaN(d.getTime())
)
10 changes: 10 additions & 0 deletions packages/date/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
},
"include": [
"src"
]
}
3 changes: 3 additions & 0 deletions packages/error/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"url": "git+https://github.com/kanziw/kanziwjs.git",
"directory": "packages/error"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/kanziw/kanziwjs/tree/main/packages/error#readme",
"keywords": [
"error",
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-config-kanziw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"url": "git+https://github.com/kanziw/kanziwjs.git",
"directory": "packages/eslint-config-kanziw"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/kanziw/kanziwjs/tree/main/packages/eslint-config-kanziw#readme",
"keywords": [
"eslint",
Expand Down
3 changes: 3 additions & 0 deletions packages/time/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"url": "git+https://github.com/kanziw/kanziwjs.git",
"directory": "packages/time"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/kanziw/kanziwjs/tree/main/packages/time#readme",
"keywords": [
"time",
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,18 @@ __metadata:
languageName: unknown
linkType: soft

"@kanziw/date@workspace:packages/date":
version: 0.0.0-use.local
resolution: "@kanziw/date@workspace:packages/date"
dependencies:
"@types/jest": ^27.5.0
"@types/node": ^17.0.25
publish-if-not-published: ^3.1.2
rimraf: ^3.0.2
typescript: ^4.6.3
languageName: unknown
linkType: soft

"@kanziw/error@workspace:packages/error":
version: 0.0.0-use.local
resolution: "@kanziw/error@workspace:packages/error"
Expand Down