diff --git a/bun.lockb b/bun.lockb index dbb396c..e144556 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 40e4085..380cd91 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@curiousleaf/utils", "description": "A lightweight set of utilities", - "version": "1.0.27", + "version": "1.0.28", "license": "MIT", "type": "module", "author": { @@ -26,7 +26,7 @@ "devDependencies": { "@babel/runtime": "^7.23.8", "@biomejs/biome": "^1.7.1", - "bun-types": "latest", + "@types/bun": "^1.1.2", "prettier": "^3.1.1", "typescript": "^5.3.3" }, diff --git a/src/index.ts b/src/index.ts index 25797fc..847a904 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ // External exports export * from "scule" +export * from "@uiw/color-convert" // Internal exports export * from "./colors/colors" diff --git a/src/numbers/numbers.test.ts b/src/numbers/numbers.test.ts index 651c2d0..4b75588 100644 --- a/src/numbers/numbers.test.ts +++ b/src/numbers/numbers.test.ts @@ -34,7 +34,7 @@ describe("parseNumericValue", () => { }) it("returns the original string if it cannot be parsed", () => { - expect(parseNumericValue("not a number")).toBe(undefined) + expect(parseNumericValue("not a number")).toBeUndefined() }) }) diff --git a/src/random/random.test.ts b/src/random/random.test.ts index 3d2422c..01d72b7 100644 --- a/src/random/random.test.ts +++ b/src/random/random.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "bun:test" -import { getRandomColor, getRandomNumber, getRandomProperty, getRandomString } from "./random" +import { getRandomColor, getRandomElement, getRandomNumber, getRandomProperty, getRandomString } from "./random" describe("getRandomColor", () => { it("returns a string", () => { @@ -43,6 +43,14 @@ describe("getRandomNumber", () => { }) }) +describe("getRandomElement", () => { + it("returns a value from the array", () => { + const array = [1, 2, 3] + const result = getRandomElement(array) + expect([1, 2, 3]).toContain(result) + }) +}) + describe("getRandomProperty", () => { it("returns a value from the object", () => { const obj = { a: 1, b: 2, c: 3 } diff --git a/src/random/random.ts b/src/random/random.ts index 7e3520c..19cc1e7 100644 --- a/src/random/random.ts +++ b/src/random/random.ts @@ -31,6 +31,17 @@ export const getRandomNumber = (min: number, max: number) => { return Math.floor(Math.random() * (max - min + 1)) + min } +/** + * Returns a random element from an array. + * + * @param array - The array to get a random element from. + * @returns A random element from the array. + */ +export const getRandomElement = (array: T[]): T => { + const index = Math.floor(Math.random() * array.length) + return array[index]! +} + /** * Returns a random property value from an object. * @param obj - The object to get a random property value from. diff --git a/tsconfig.json b/tsconfig.json index 31e921e..7b4f9f7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -103,10 +103,8 @@ "allowUnreachableCode": true /* Disable error reporting for unreachable code. */, /* Completeness */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */, + "skipLibCheck": true /* Skip type checking all .d.ts files. */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - - "types": ["bun-types"] /* Add Bun global */ }, "include": ["src"],