diff --git a/packages/@weresk/core/CHANGELOG.md b/packages/@weresk/core/CHANGELOG.md index 1d68502..0bc1e57 100644 --- a/packages/@weresk/core/CHANGELOG.md +++ b/packages/@weresk/core/CHANGELOG.md @@ -1,5 +1,11 @@ # @weresk/core +## 0.2.10 + +### Patch Changes + +- Adding new utils + ## 0.2.9 ### Patch Changes diff --git a/packages/@weresk/core/README.md b/packages/@weresk/core/README.md index 79ecc57..61edfa0 100644 --- a/packages/@weresk/core/README.md +++ b/packages/@weresk/core/README.md @@ -25,6 +25,9 @@ Common utilities and types for the rest of @weresk libraries ## Utils +- **Arrays** + - **`pickRandom(array?: T[]): T | undefined`**: Returns a random element from an array + - **`shuffle(array: T[]): T[]`**: Shuffles an array - **Objects** - **`isObject(item?: any): boolean`**: Checks if a variable is an object and not an array - **`mapKeys(keys: K[], fn: (arg: K) => T): Record`**: Creates an object from an array of keys, using map function @@ -33,6 +36,7 @@ Common utilities and types for the rest of @weresk libraries - **`purgeEmptyStrings(obj: T): Partial`**: Converts empty strings in the object values to `undefined` - **Styles** - **`colorToRGB(color: Color): string`**: Converts Sanity Color object to `R G B` string + - **`lockBodyScroll(lock = true)`**: Locks and unlocks scroll for HTML body element - **Text** - **`caseTransform(input: string | undefined, transform: "capitalize" | "uppercase" | "lowercase" | "title"): string`**: Transforms a string case - **`capitalize(input: string | undefined): string`**: Capitalizes a string diff --git a/packages/@weresk/core/package.json b/packages/@weresk/core/package.json index 36e8664..4c8eb29 100755 --- a/packages/@weresk/core/package.json +++ b/packages/@weresk/core/package.json @@ -1,6 +1,6 @@ { "name": "@weresk/core", - "version": "0.2.9", + "version": "0.2.10", "private": false, "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/packages/@weresk/core/src/types/props.ts b/packages/@weresk/core/src/types/props.ts index 38e0589..736b695 100755 --- a/packages/@weresk/core/src/types/props.ts +++ b/packages/@weresk/core/src/types/props.ts @@ -7,6 +7,7 @@ export interface DefaultStyleProps { export interface DefaultProps extends DefaultStyleProps { id?: string; + title?: string; } export interface DefaultPropsWithChildren extends DefaultProps { diff --git a/packages/@weresk/core/src/utils/arrays/index.ts b/packages/@weresk/core/src/utils/arrays/index.ts new file mode 100644 index 0000000..74d840a --- /dev/null +++ b/packages/@weresk/core/src/utils/arrays/index.ts @@ -0,0 +1,2 @@ +export * from "./pickRandom"; +export * from "./shuffle"; diff --git a/packages/@weresk/core/src/utils/arrays/pickRandom.ts b/packages/@weresk/core/src/utils/arrays/pickRandom.ts new file mode 100644 index 0000000..4208cfc --- /dev/null +++ b/packages/@weresk/core/src/utils/arrays/pickRandom.ts @@ -0,0 +1,4 @@ +export function pickRandom(array?: T[]): T | undefined { + if (!array?.length) return undefined; + return array[Math.floor(Math.random() * array.length)]; +} diff --git a/packages/@weresk/core/src/utils/arrays/shuffle.ts b/packages/@weresk/core/src/utils/arrays/shuffle.ts new file mode 100644 index 0000000..ee9c2b6 --- /dev/null +++ b/packages/@weresk/core/src/utils/arrays/shuffle.ts @@ -0,0 +1,16 @@ +export function shuffle(array: T[]): T[] { + let currentIndex = array.length; + let randomIndex: number; + + // While there remain elements to shuffle. + while (currentIndex > 0) { + // Pick a remaining element. + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex--; + + // And swap it with the current element. + [array[currentIndex], array[randomIndex]] = [array[randomIndex] as T, array[currentIndex] as T]; + } + + return array; +} diff --git a/packages/@weresk/core/src/utils/styles/index.ts b/packages/@weresk/core/src/utils/styles/index.ts index 7bb4d13..97fb5c8 100755 --- a/packages/@weresk/core/src/utils/styles/index.ts +++ b/packages/@weresk/core/src/utils/styles/index.ts @@ -1 +1,2 @@ -export { colorToRGB } from "./colorToRgb"; +export * from "./colorToRgb"; +export * from "./lockBodyScroll"; diff --git a/packages/@weresk/core/src/utils/styles/lockBodyScroll.ts b/packages/@weresk/core/src/utils/styles/lockBodyScroll.ts new file mode 100644 index 0000000..87a3071 --- /dev/null +++ b/packages/@weresk/core/src/utils/styles/lockBodyScroll.ts @@ -0,0 +1,4 @@ +export function lockBodyScroll(lock = true) { + const body = document.querySelector("body"); + body?.style.setProperty("overflow", lock ? "hidden" : "auto"); +} diff --git a/packages/@weresk/maket/CHANGELOG.md b/packages/@weresk/maket/CHANGELOG.md index 8dfc013..af99c5e 100644 --- a/packages/@weresk/maket/CHANGELOG.md +++ b/packages/@weresk/maket/CHANGELOG.md @@ -1,5 +1,13 @@ # @weresk/maket +## 0.2.19 + +### Patch Changes + +- Updated dependencies + - @weresk/core@0.2.10 + - @weresk/locales@0.0.12 + ## 0.2.18 ### Patch Changes diff --git a/packages/@weresk/maket/package.json b/packages/@weresk/maket/package.json index a731bc5..c834000 100755 --- a/packages/@weresk/maket/package.json +++ b/packages/@weresk/maket/package.json @@ -1,6 +1,6 @@ { "name": "@weresk/maket", - "version": "0.2.18", + "version": "0.2.19", "private": false, "exports": { ".": {