-
Notifications
You must be signed in to change notification settings - Fork 25
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
71c183f
commit 184cf1c
Showing
29 changed files
with
858 additions
and
264 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
.cache | ||
.DS_Store | ||
.env | ||
.env.development.local | ||
.env.local | ||
.env.test | ||
.eslintcache | ||
.git | ||
.next | ||
.node_repl_history | ||
.nova | ||
.now | ||
.npm | ||
.sentryclirc | ||
.tmp | ||
.turbo | ||
.vercel | ||
.vscode | ||
out | ||
.yarn | ||
.yarn-integrity | ||
*.lcov | ||
*.log | ||
*.pid | ||
*.pid.lock | ||
*.seed | ||
*.tsbuildinfo | ||
# next-env.d.ts | ||
coverage | ||
dist | ||
dist-demo | ||
node_modules | ||
yarn-error.log | ||
logs | ||
node_modules/ | ||
npm-debug.log* | ||
pids | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
typings/ | ||
yarn-debug.log* | ||
yarn-error.log* |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.git | ||
.env | ||
node_modules |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": true | ||
} |
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
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"name": "@heliosgraphics/library", | ||
"version": "4.0.0-alpha-5", | ||
"version": "4.1.0", | ||
"private": false, | ||
"type": "module", | ||
"author": "Chris Puska <03b8@helios.graphics>", | ||
"description": "Atomic CSS Library", | ||
"author": "03b8 <03b8@helios.graphics>", | ||
"description": "Helios Library", | ||
"main": "./src/index", | ||
"devDependencies": { | ||
"csstype": "^3.1.3" | ||
"csstype": "latest" | ||
} | ||
} |
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,30 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { copyValue } from './clipboard' | ||
|
||
const TEXT_STRING = 'Test text' as const; | ||
|
||
describe('copyValue', () => { | ||
it('copies text to the clipboard', () => { | ||
const createElementMock: any = { | ||
value: '', | ||
select: vi.fn(), | ||
remove: vi.fn(), | ||
}; | ||
|
||
const spyCreateElement = vi.spyOn(document, 'createElement').mockImplementation(() => createElementMock); | ||
const spyAppendChild = vi.spyOn(document.body, 'appendChild').mockImplementation(node => node); | ||
|
||
document.execCommand = vi.fn(); | ||
|
||
copyValue(TEXT_STRING); | ||
expect(spyCreateElement).toHaveBeenCalledWith('input'); | ||
expect(spyAppendChild).toHaveBeenCalled(); | ||
expect(document.execCommand).toHaveBeenCalledWith('copy', false); | ||
|
||
const inputElement: HTMLInputElement = spyCreateElement.mock.results[0].value; | ||
expect(inputElement.value).toBe(TEXT_STRING); | ||
|
||
spyCreateElement.mockRestore(); | ||
spyAppendChild.mockRestore(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
export const copyValue = (text: string) => { | ||
const inp = document.createElement('input'); | ||
// copies the given value to the clipboard. | ||
export const copyValue = (text: string): void => { | ||
const input: HTMLInputElement = document.createElement('input'); | ||
|
||
document.body.appendChild(inp); | ||
inp.value = text; | ||
inp.select(); | ||
document.body.appendChild(input); | ||
input.value = text; | ||
input.select(); | ||
document.execCommand('copy', false); | ||
|
||
return inp.remove(); | ||
return input.remove(); | ||
}; |
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 |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { rgbToHex } from './colors' | ||
import { it, describe, expect } from 'vitest'; | ||
import { rgbToHex, hexToRgb, DEFAULT_PROFILE_RGB } from './colors' | ||
|
||
describe('colors', () => { | ||
describe('hexToRgb', () => { | ||
it('converts hex to rgb', () => expect(hexToRgb('#0c2c78')).toEqual([12, 44, 120])); | ||
it('returns default for 0', () => expect(hexToRgb(<any>0)).toEqual(DEFAULT_PROFILE_RGB)); | ||
it('returns default for undefined', () => expect(hexToRgb(<any>undefined)).toEqual(DEFAULT_PROFILE_RGB)); | ||
}); | ||
|
||
describe('rgbToHex', () => { | ||
it('converts rgb to hex', () => expect(rgbToHex(12, 44, 120)).toEqual('#0c2c78')); | ||
it('converts strings to hex', () => expect(rgbToHex('12' as any as number, '44' as any as number, '120' as any as number)).toEqual('#ffffff')); | ||
it('converts even with a null input to hex', () => expect(rgbToHex(null as any, 44, 120)).toEqual('#ff2c78')); | ||
it('converts undefined to hex', () => expect(rgbToHex(12, undefined as any, 120)).toEqual('#0cff78')); | ||
it('converts string to hex', () => expect(rgbToHex(<any>'12', <any>'44', <any>'120')).toEqual('#0c2c78')); | ||
it('converts null to hex', () => expect(rgbToHex(<any>null, 44, 120)).toEqual('#002c78')); | ||
it('returns undefined to hex', () => expect(rgbToHex(12, <any>undefined, 120)).toEqual('#0cff78')); | ||
}); | ||
}); |
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,41 @@ | ||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
import { debounce, type CallbackFunction } from './debounce' | ||
|
||
describe('debounce', () => { | ||
let callback: CallbackFunction; | ||
let debouncedFunction: CallbackFunction; | ||
|
||
beforeEach(() => { | ||
vi.useFakeTimers(); | ||
|
||
callback = vi.fn(); | ||
debouncedFunction = debounce(callback, 1000); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.useRealTimers(); | ||
}); | ||
|
||
it('calls the callback after the specified time', () => { | ||
debouncedFunction(); | ||
|
||
vi.advanceTimersByTime(500); | ||
expect(callback).not.toHaveBeenCalled(); | ||
|
||
vi.advanceTimersByTime(500); | ||
expect(callback).toHaveBeenCalled(); | ||
}); | ||
|
||
it('does not call the callback if the function is called again within the wait time', () => { | ||
debouncedFunction(); | ||
vi.advanceTimersByTime(500); | ||
|
||
debouncedFunction(); | ||
vi.advanceTimersByTime(500); | ||
|
||
expect(callback).not.toHaveBeenCalled(); | ||
|
||
vi.advanceTimersByTime(500); | ||
expect(callback).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,15 +1,16 @@ | ||
{ | ||
"name": "@heliosgraphics/utils", | ||
"version": "4.0.0-alpha-5", | ||
"version": "4.1.0", | ||
"private": false, | ||
"type": "module", | ||
"author": "Chris Puska <03b8@helios.graphics>", | ||
"author": "03b8 <03b8@helios.graphics>", | ||
"description": "Helios Utils", | ||
"dependencies": { | ||
"@heliosgraphics/library": "latest", | ||
"uuid": "^9.0.1", | ||
"xss": "^1.0.14" | ||
}, | ||
"devDependencies": { | ||
"@types/uuid": "9.0.7" | ||
"@types/uuid": "latest" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
import { getSlug } from "./slug"; | ||
import { it, describe, expect } from 'vitest'; | ||
import { getSlug } from "./slug"; | ||
|
||
describe('slug', () => { | ||
|
||
describe('getSlug', () => { | ||
// Good | ||
it('Gets a lowercase subdomain from case 1', () => expect(getSlug('--BuRn--')).toEqual('-burn-')); | ||
it('Gets a lowercase subdomain from case 2', () => expect(getSlug('#$%^B#uR#n-')).toEqual('burn-')); | ||
it('Gets a nice slug for a category', () => expect(getSlug('Gaussian Blur')).toEqual('gaussian-blur')); | ||
|
||
// Empty | ||
it('Gets empty string if subdomain is undefined', () => expect(getSlug(undefined)).toEqual('')); | ||
it('returns valid from string with dashes', () => expect(getSlug('--B—uRn--')).toEqual('-burn-')); | ||
it('returns valid from special string', () => expect(getSlug('#$%^B#uR#n-')).toEqual('burn-')); | ||
it('returns valid from parens string', () => expect(getSlug('Gaussian Blur [1](2){3}')).toEqual('gaussian-blur-123')); | ||
it('replaces àáäâèéëêìíïîòóöôùúüûñç', () => expect(getSlug('àáäâèéëêìíïîòóöôùúüûñç')).toEqual('aaaaeeeeiiiioooouuuunc')); | ||
it('fails silently from undefined', () => expect(getSlug(undefined)).toEqual('')); | ||
it('fails silently from null', () => expect(getSlug(<any>null)).toEqual('')); | ||
}); | ||
}); |
Oops, something went wrong.