@nothing-but/utils
Advanced tools
Comparing version 0.2.0 to 0.2.2
@@ -1,7 +0,7 @@ | ||
export { binaryInsert, binaryInsertUnique, binaryInsertWith, binarySearch, binarySearchWith, deduped, equals, includesSameMembers, mutateFilter, pickRandom, pickRandomExclidingOne, randomIterate, remove, wrap } from '../chunk/TULCZLWC.js'; | ||
export { binaryInsert, binaryInsertUnique, binaryInsertWith, binarySearch, binarySearchWith, deduped, equals, includesSameMembers, mutateFilter, pickRandom, pickRandomExclidingOne, randomIterate, remove, wrap } from '../chunk/HSNCKYHC.js'; | ||
import '../chunk/OZRPOR2F.js'; | ||
import '../chunk/I42HF3LR.js'; | ||
import '../chunk/77EWK6YV.js'; | ||
import '../chunk/233FGWLT.js'; | ||
import '../chunk/PSUTF5FZ.js'; | ||
import '../chunk/UVHYI4PJ.js'; | ||
import '../chunk/5ZKAE4VZ.js'; | ||
import '../chunk/QR25BPRP.js'; |
@@ -5,3 +5,3 @@ export { a as array } from '../array-2ae64097.js'; | ||
export { m as misc } from '../misc-515f5ec0.js'; | ||
export { t as trig } from '../trig-3450e0d6.js'; | ||
export { t as trig } from '../trig-3bf85b12.js'; | ||
export { t as types } from '../types-053e3c12.js'; |
@@ -1,7 +0,7 @@ | ||
export { array_exports as array } from '../chunk/TULCZLWC.js'; | ||
export { array_exports as array } from '../chunk/HSNCKYHC.js'; | ||
export { ease_exports as ease } from '../chunk/OZRPOR2F.js'; | ||
export { math_exports as math } from '../chunk/I42HF3LR.js'; | ||
export { math_exports as math } from '../chunk/77EWK6YV.js'; | ||
export { misc_exports as misc } from '../chunk/233FGWLT.js'; | ||
export { trig_exports as trig } from '../chunk/PSUTF5FZ.js'; | ||
export { trig_exports as trig } from '../chunk/UVHYI4PJ.js'; | ||
import '../chunk/5ZKAE4VZ.js'; | ||
export { types_exports as types } from '../chunk/QR25BPRP.js'; |
@@ -1,2 +0,2 @@ | ||
export { between, bounce, clamp, mapRange, numberEquals, random, randomFrom, randomInt, randomIntFrom, rangesIntersecting, remainder, toPercent, wrap } from '../chunk/I42HF3LR.js'; | ||
export { between, bounce, clamp, mapRange, numberEquals, random, randomFrom, randomInt, randomIntFrom, rangesIntersecting, remainder, toPercent, wrap } from '../chunk/77EWK6YV.js'; | ||
import '../chunk/5ZKAE4VZ.js'; |
import '../types-053e3c12.js'; | ||
export { F as Force, S as Segment, a as Vec, V as VecString, Z as ZERO, o as force, p as forceToVec, v as vec, e as vecAdd, l as vecAngle, d as vecDifference, k as vecDistance, i as vecDivide, b as vecEquals, g as vecMultiply, h as vecProduct, j as vecQuotient, m as vecRotate, n as vecRotateAround, c as vecSubtract, f as vecSum, z as zero } from '../trig-3450e0d6.js'; | ||
export { F as Force, S as Segment, a as Vector, V as VectorString, Z as ZERO, o as force, p as forceTovector, v as vector, e as vectorAdd, l as vectorAngle, d as vectorDifference, k as vectorDistance, i as vectorDivide, b as vectorEquals, g as vectorMultiply, h as vectorProduct, j as vectorQuotient, m as vectorRotate, n as vectorRotateAround, c as vectorSubtract, f as vectorSum, z as zero } from '../trig-3bf85b12.js'; |
@@ -1,2 +0,2 @@ | ||
export { Force, Vec, ZERO, force, forceToVec, vec, vecAdd, vecAngle, vecDifference, vecDistance, vecDivide, vecEquals, vecMultiply, vecProduct, vecQuotient, vecRotate, vecRotateAround, vecSubtract, vecSum, zero } from '../chunk/PSUTF5FZ.js'; | ||
export { Force, Vector, ZERO, force, forceTovector, vector, vectorAdd, vectorAngle, vectorDifference, vectorDistance, vectorDivide, vectorEquals, vectorMultiply, vectorProduct, vectorQuotient, vectorRotate, vectorRotateAround, vectorSubtract, vectorSum, zero } from '../chunk/UVHYI4PJ.js'; | ||
import '../chunk/5ZKAE4VZ.js'; |
{ | ||
"name": "@nothing-but/utils", | ||
"version": "0.2.0", | ||
"version": "0.2.2", | ||
"license": "MIT", | ||
@@ -21,7 +21,13 @@ "author": "Damian Tarnawski <gthetarnav@gmail.com>", | ||
"type": "module", | ||
"main": "./dist/array/index.js", | ||
"module": "./dist/array/index.js", | ||
"types": "./dist/array/index.d.ts", | ||
"main": "./dist/index/index.js", | ||
"module": "./dist/index/index.js", | ||
"types": "./dist/index/index.d.ts", | ||
"browser": {}, | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/index/index.d.ts", | ||
"default": "./dist/index/index.js" | ||
} | ||
}, | ||
"./array": { | ||
@@ -39,8 +45,2 @@ "import": { | ||
}, | ||
".": { | ||
"import": { | ||
"types": "./dist/index/index.d.ts", | ||
"default": "./dist/index/index.js" | ||
} | ||
}, | ||
"./math": { | ||
@@ -47,0 +47,0 @@ "import": { |
@@ -18,4 +18,4 @@ export const random = (max: number) => Math.random() * max | ||
const range = max - min, | ||
remainder = wrap(value - min, 0, 2 * range), | ||
distance = Math.abs(remainder - range) | ||
rem = wrap(value - min, 0, 2 * range), | ||
distance = Math.abs(rem - range) | ||
return max - distance | ||
@@ -22,0 +22,0 @@ } |
@@ -8,3 +8,3 @@ import type { Position } from './types' | ||
*/ | ||
export type VecString = `(${number}, ${number})` | ||
export type VectorString = `(${number}, ${number})` | ||
@@ -14,3 +14,3 @@ /** | ||
*/ | ||
export class Vec { | ||
export class Vector { | ||
x: number | ||
@@ -20,3 +20,3 @@ y: number | ||
/** | ||
* Creates a new Vec instance. | ||
* Creates a new vector instance. | ||
* @param str - A string in the format `(${number}, ${number})`. | ||
@@ -33,6 +33,6 @@ * | ||
*/ | ||
constructor(str: VecString) | ||
constructor(str: VectorString) | ||
constructor(vec: Position) | ||
constructor(x: number, y?: number) | ||
constructor(x: number | VecString | Position, y?: number) { | ||
constructor(x: number | VectorString | Position, y?: number) { | ||
if (typeof x === 'string') { | ||
@@ -54,3 +54,3 @@ const [xStr, yStr] = x.slice(1, -1).split(', ') | ||
} | ||
toString(): VecString { | ||
toString(): VectorString { | ||
return `(${this.x}, ${this.y})` | ||
@@ -64,20 +64,20 @@ } | ||
/** | ||
* Creates a new Vec instance. | ||
* Creates a new vector instance. | ||
*/ | ||
export const vec: { | ||
(str: VecString): Vec | ||
(vec: Position): Vec | ||
(x: number, y?: number): Vec | ||
} = (...args: [any]) => new Vec(...args) | ||
export const vector: { | ||
(str: VectorString): Vector | ||
(vector: Position): Vector | ||
(x: number, y?: number): Vector | ||
} = (...args: [any]) => new Vector(...args) | ||
/** | ||
* A constant Vec representing the zero vector. | ||
* A constant vector representing the zero vector. | ||
*/ | ||
export const ZERO = vec(0, 0) | ||
export const ZERO = vector(0, 0) | ||
/** | ||
* Creates a new Vec instance representing the zero vector. | ||
* @returns A Vec instance representing the zero vector. | ||
* Creates a new vector instance representing the zero vector. | ||
* @returns A vector instance representing the zero vector. | ||
*/ | ||
export const zero = () => vec(0, 0) | ||
export const zero = () => vector(0, 0) | ||
@@ -87,3 +87,3 @@ /** | ||
*/ | ||
export function vecEquals(a: Vec, b: Vec): boolean { | ||
export function vectorEquals(a: Vector, b: Vector): boolean { | ||
return a.x === b.x && a.y === b.y | ||
@@ -95,3 +95,3 @@ } | ||
*/ | ||
export function vecSubtract(a: Vec, b: Vec): void { | ||
export function vectorSubtract(a: Vector, b: Vector): void { | ||
a.x -= b.x | ||
@@ -105,4 +105,4 @@ a.y -= b.y | ||
*/ | ||
export function vecDifference(a: Vec, b: Vec): Vec { | ||
return vec(a.x - b.x, a.y - b.y) | ||
export function vectorDifference(a: Vector, b: Vector): Vector { | ||
return vector(a.x - b.x, a.y - b.y) | ||
} | ||
@@ -113,5 +113,5 @@ | ||
*/ | ||
export function vecAdd(vec: Vec, velocity: Vec | Force | number): void | ||
export function vecAdd(vec: Vec, x: number, y: number): void | ||
export function vecAdd(vec: Vec, x: Vec | Force | number, y?: number): void { | ||
export function vectorAdd(vec: Vector, velocity: Vector | Force | number): void | ||
export function vectorAdd(vec: Vector, x: number, y: number): void | ||
export function vectorAdd(vec: Vector, x: Vector | Force | number, y?: number): void { | ||
if (typeof x === 'number') { | ||
@@ -123,3 +123,3 @@ vec.x += x | ||
if (x instanceof Force) { | ||
x = forceToVec(x) | ||
x = forceTovector(x) | ||
} | ||
@@ -134,4 +134,4 @@ vec.x += x.x | ||
*/ | ||
export function vecSum(a: Vec, b: Vec): Vec { | ||
return vec(a.x + b.x, a.y + b.y) | ||
export function vectorSum(a: Vector, b: Vector): Vector { | ||
return vector(a.x + b.x, a.y + b.y) | ||
} | ||
@@ -142,3 +142,3 @@ | ||
*/ | ||
export function vecMultiply(a: Vec, b: Vec | number): void { | ||
export function vectorMultiply(a: Vector, b: Vector | number): void { | ||
if (typeof b === 'number') { | ||
@@ -157,4 +157,4 @@ a.x *= b | ||
*/ | ||
export function vecProduct(a: Vec, b: Vec): Vec { | ||
return vec(a.x * b.x, a.y * b.y) | ||
export function vectorProduct(a: Vector, b: Vector): Vector { | ||
return vector(a.x * b.x, a.y * b.y) | ||
} | ||
@@ -165,3 +165,3 @@ | ||
*/ | ||
export function vecDivide(a: Vec, b: Vec): void { | ||
export function vectorDivide(a: Vector, b: Vector): void { | ||
a.x /= b.x | ||
@@ -176,4 +176,4 @@ a.y /= b.y | ||
*/ | ||
export function vecQuotient(a: Vec, b: Vec): Vec { | ||
return vec(a.x / b.x, a.y / b.y) | ||
export function vectorQuotient(a: Vector, b: Vector): Vector { | ||
return vector(a.x / b.x, a.y / b.y) | ||
} | ||
@@ -185,3 +185,3 @@ | ||
*/ | ||
export function vecDistance(a: Vec, b: Vec): number { | ||
export function vectorDistance(a: Vector, b: Vector): number { | ||
const x = a.x - b.x | ||
@@ -196,3 +196,3 @@ const y = a.y - b.y | ||
*/ | ||
export function vecAngle(a: Vec, b: Vec): number { | ||
export function vectorAngle(a: Vector, b: Vector): number { | ||
return Math.atan2(b.y - a.y, b.x - a.x) | ||
@@ -205,3 +205,3 @@ } | ||
*/ | ||
export function vecRotate(point: Vec, rad: number): void { | ||
export function vectorRotate(point: Vector, rad: number): void { | ||
const { x, y } = point, | ||
@@ -221,3 +221,3 @@ cos = Math.cos(rad), | ||
*/ | ||
export function vecRotateAround(point: Vec, origin: Vec, rad: number): void { | ||
export function vectorRotateAround(point: Vector, origin: Vector, rad: number): void { | ||
const { x, y } = point, | ||
@@ -255,8 +255,8 @@ { x: ox, y: oy } = origin, | ||
*/ | ||
constructor(delta_x: Vec, delta_y: Vec) | ||
constructor(delta_x: Vector, delta_y: Vector) | ||
constructor(distance: number, angle: number) | ||
constructor(a: number | Vec, b: number | Vec) { | ||
constructor(a: number | Vector, b: number | Vector) { | ||
if (typeof a === 'object') { | ||
this.angle = vecAngle(a, b as Vec) | ||
this.distance = vecDistance(a, b as Vec) | ||
this.angle = vectorAngle(a, b as Vector) | ||
this.distance = vectorDistance(a, b as Vector) | ||
} else { | ||
@@ -278,3 +278,3 @@ this.distance = a | ||
export const force: { | ||
(a: Vec, b: Vec): Force | ||
(a: Vector, b: Vector): Force | ||
(distance: number, angle: number): Force | ||
@@ -284,7 +284,7 @@ } = (...args: [any, any]) => new Force(...args) | ||
/** | ||
* Converts a Force object to a Vec object with x and y components. | ||
* Converts a Force object to a vector object with x and y components. | ||
*/ | ||
export function forceToVec(force: Force): Vec | ||
export function forceToVec(distance: number, angle: number): Vec | ||
export function forceToVec(distance: number | Force, angle?: number): Vec { | ||
export function forceTovector(f: Force): Vector | ||
export function forceTovector(distance: number, angle: number): Vector | ||
export function forceTovector(distance: number | Force, angle?: number): Vector { | ||
if (typeof distance === 'object') { | ||
@@ -296,3 +296,3 @@ angle = distance.angle | ||
const y = distance * Math.sin(angle!) | ||
return vec(x, y) | ||
return vector(x, y) | ||
} | ||
@@ -303,2 +303,2 @@ | ||
*/ | ||
export type Segment = [Vec, Vec] | ||
export type Segment = [Vector, Vector] |
import fs from 'fs' | ||
import path from 'path' | ||
import { defineConfig } from 'tsup-preset-solid' | ||
import { defineConfig } from 'tsup' | ||
import * as preset from 'tsup-preset-solid' | ||
@@ -8,9 +9,28 @@ const src = path.resolve(__dirname, 'src') | ||
export default defineConfig( | ||
entries.map(entry => ({ entry: path.join(src, entry) })), | ||
{ | ||
// Enable this to write export conditions to package.json | ||
writePackageJson: true, | ||
dropConsole: true, | ||
}, | ||
) | ||
const preset_options: preset.PresetOptions = { | ||
entries: entries.map(entry => ({ entry: path.join(src, entry) })), | ||
drop_console: true, | ||
} | ||
const CI = | ||
process.env['CI'] === 'true' || | ||
process.env['CI'] === '"1"' || | ||
process.env['GITHUB_ACTIONS'] === 'true' || | ||
process.env['GITHUB_ACTIONS'] === '"1"' | ||
export default defineConfig(config => { | ||
const watching = !!config.watch | ||
const parsed_options = preset.parsePresetOptions(preset_options, watching) | ||
if (!watching && !CI) { | ||
const package_fields = preset.generatePackageExports(parsed_options) | ||
/* | ||
will update ./package.json with the correct export fields | ||
*/ | ||
preset.writePackageJson(package_fields) | ||
} | ||
return preset.generateTsupOptions(parsed_options) | ||
}) |
83433
2332