-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90ff878
commit 0f65167
Showing
16 changed files
with
204 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { | ||
getMonthOptions, | ||
getYearOptions, | ||
parseAndFormatDate, | ||
parseAndFormatTime, | ||
formatDateOnly, | ||
} from '../index' | ||
|
||
describe('time', () => { | ||
it('can generate month options', () => { | ||
expect(getMonthOptions()).toHaveLength(12) | ||
}) | ||
it('can generate year options', () => { | ||
const currentYear = new Date().getFullYear() | ||
expect(getYearOptions(currentYear)).toHaveLength(1) | ||
}) | ||
it('can parse date', () => { | ||
expect(parseAndFormatDate('2024-09-20T11:16:49.96+01:00')).toEqual('20/09/2024 11:16:49') | ||
}) | ||
it('can parse time', () => { | ||
expect(parseAndFormatTime('2024-09-20T11:16:49.96+01:00')).toEqual('11:16') | ||
}) | ||
it('can format date only', () => { | ||
expect(formatDateOnly(new Date('2024-09-20T11:16:49.96+01:00'))).toEqual('2024-09-20') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { renderHook } from '@testing-library/react' | ||
import { describe, expect, it, vi } from 'vitest' | ||
import {useForm} from '..' | ||
|
||
vi.mock('next/router', () => require('next-router-mock')); | ||
|
||
describe('useForm', () => { | ||
it('useForm should not be undefined', () => { | ||
const { result } = renderHook(() => useForm()) | ||
expect(result.current).not.toBeUndefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { renderHook } from '@testing-library/react' | ||
import { describe, expect, it } from 'vitest' | ||
import {useGet} from '..' | ||
|
||
describe('useGet', () => { | ||
it('useGet isLoading should be true', () => { | ||
const { result } = renderHook(() => useGet('https://jsonplaceholder.typicode.com/todos/1')) | ||
expect(result.current.isLoading).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist/ | ||
coverage/ | ||
node_modules | ||
.reports/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**/__tests__/** | ||
src | ||
!.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# `@glocurrency/uuid` | ||
|
||
UUID Helpers | ||
|
||
--- | ||
|
||
## Install | ||
|
||
```bash | ||
$ pnpm add @glocurrency/uuid | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import { first8 } from '@glocurrency/uuid' | ||
|
||
first8('c4e4b3e4-4b3e-4c4e-b3e4-c4e4b3e4b3e4') // c4e4b3e4 | ||
``` | ||
|
||
## Authors | ||
|
||
- [Ivan Stasiuk](https://github.com/brokeyourbike) | [Twitter](https://twitter.com/brokeyourbike) | [LinkedIn](https://www.linkedin.com/in/brokeyourbike) | [stasi.uk](https://stasi.uk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@glocurrency/uuid", | ||
"description": "UUID Helpers", | ||
"version": "0.0.3", | ||
"type": "module", | ||
"engines": { | ||
"node": ">=20.x" | ||
}, | ||
"main": "./dist/index.cjs", | ||
"sideEffects": false, | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.cjs", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"prebuild": "shx rm -rf dist", | ||
"typecheck": "tsc --noEmit", | ||
"type:generate": "tsc --declaration -p tsconfig.build.json", | ||
"build": "vite build --config vite.config.ts && pnpm run type:generate", | ||
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts", | ||
"test:unit": "vitest --run --config vite.config.ts", | ||
"test:unit:coverage": "pnpm test:unit --coverage" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/glocurrency/commons.ts", | ||
"directory": "packages/uuid" | ||
}, | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { | ||
first8, | ||
slim, | ||
} from '../index' | ||
|
||
describe('uuid', () => { | ||
it('can get first 8 chars', () => { | ||
expect(first8('a322523d-2a01-407f-8d28-4fbcbc011370')).toBe('a322523d') | ||
}) | ||
it('can work with empty string', () => { | ||
expect(first8('')).toBe('') | ||
}) | ||
it('can slim uuid', () => { | ||
expect(slim('a322523d-2a01-407f-8d28-4fbcbc011370')).toBe('a322523d2a01407f8d284fbcbc011370') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const first8 = (value: string): string => { | ||
return value.slice(0, 8) | ||
} | ||
|
||
export const slim = (value: string): string => { | ||
return value.replace(/-/g, ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"emitDeclarationOnly": true, | ||
"rootDir": "src", | ||
"outDir": "dist" | ||
}, | ||
"exclude": [ | ||
"*.config.ts", | ||
"*.setup.ts", | ||
"**/__tests__", | ||
"**/__mocks__", | ||
"src/**/*.test.tsx" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src/**/*.ts", "src/**/*.tsx", "*.config.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig, mergeConfig } from 'vite' | ||
import { defaultConfig } from '../../vite.config' | ||
|
||
export default mergeConfig(defineConfig(defaultConfig), { | ||
build: { | ||
target: ['node20'], | ||
}, | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.