New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nothing-but/utils

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nothing-but/utils - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

6

CHANGELOG.md
# @nothing-but/utils
## 0.4.1
### Patch Changes
- 950e9fa: Fix tree-shaking
## 0.4.0

@@ -4,0 +10,0 @@

159

dist/array/index.js

@@ -1,8 +0,151 @@

export { binary_insert, binary_insert_unique, binary_insert_with, binary_search, binary_search_with, deduped, equals, includes_same_members, mutate_filter, pick_random, pick_random_excliding_one, random_iterate, remove, wrap } from '../chunk/7MSPXAUH.js';
import '../chunk/G5UKFL7F.js';
import '../chunk/P77FFUTD.js';
import '../chunk/XW2K5NBP.js';
import '../chunk/HKPIYLA2.js';
import '../chunk/IUUNWCGK.js';
import '../chunk/5ZKAE4VZ.js';
import '../chunk/QR25BPRP.js';
import { math } from '.';
function equals(a, b) {
return a === b || a.length === b.length && a.every((e, i) => e === b[i]);
}
function wrap(arr, index) {
return arr[math.remainder(index, arr.length)];
}
function includes_same_members(a, b) {
if (a === b)
return true;
if (a.length !== b.length)
return false;
const copy = b.slice();
let found = 0;
a_loop:
for (let i = 0; i < a.length; i++) {
const a_item = a[i];
for (let j = found; j < b.length; j++) {
const b_item = copy[j];
if (a_item === b_item) {
[copy[j], copy[found]] = [copy[found], copy[j]];
found = j + 1;
continue a_loop;
}
}
return false;
}
return true;
}
function deduped(array) {
return Array.from(new Set(array));
}
function mutate_filter(array, predicate) {
const temp = array.filter(predicate);
array.length = 0;
array.push.apply(array, temp);
}
function remove(array, item) {
array.splice(array.indexOf(item), 1);
}
const pick_random = (arr) => arr[math.random_int(arr.length)];
function pick_random_excliding_one(arr, excluding) {
let pick_index = math.random_int(arr.length), pick = arr[pick_index];
if (pick === excluding) {
pick_index = (pick_index + 1) % arr.length;
pick = arr[pick_index];
}
return pick;
}
function* random_iterate(arr) {
const copy = arr.slice();
while (copy.length) {
const index = math.random_int(copy.length);
yield copy.splice(index, 1)[0];
}
}
function binary_search(arr, item) {
let low = 0, high = arr.length - 1, mid, guess;
while (low <= high) {
mid = Math.floor((low + high) / 2);
guess = arr[mid];
if (guess === item) {
return mid;
} else if (guess > item) {
high = mid - 1;
} else {
low = mid + 1;
}
}
return;
}
function binary_search_with(arr, item, get_comparable) {
const search_for = get_comparable(item);
let low = 0, high = arr.length - 1, mid, guess_item, guess_for;
while (low <= high) {
mid = low + high >> 1;
guess_item = arr[mid];
guess_for = get_comparable(guess_item);
if (guess_item === item) {
return mid;
} else if (guess_for === search_for) {
let i = mid - 1;
for (; i >= 0 && get_comparable(arr[i]) === guess_for; i--) {
if (arr[i] === item)
return i;
}
i = mid + 1;
for (; i < arr.length && get_comparable(arr[i]) === guess_for; i++) {
if (arr[i] === item)
return i;
}
} else if (guess_for > search_for) {
high = mid - 1;
} else {
low = mid + 1;
}
}
return;
}
function binary_insert_unique(arr, item) {
let low = 0, high = arr.length - 1, mid, guess;
while (low <= high) {
mid = Math.floor((low + high) / 2);
guess = arr[mid];
if (guess === item) {
return;
} else if (guess > item) {
high = mid - 1;
} else {
low = mid + 1;
}
}
arr.splice(low, 0, item);
}
function binary_insert(arr, item) {
let low = 0, high = arr.length - 1, mid, guess;
while (low <= high) {
mid = Math.floor((low + high) / 2);
guess = arr[mid];
if (guess === item) {
arr.splice(mid, 0, item);
return;
} else if (guess > item) {
high = mid - 1;
} else {
low = mid + 1;
}
}
arr.splice(low, 0, item);
}
function binary_insert_with(arr, item, get_comparable) {
const search_for = get_comparable(item);
let low = 0, high = arr.length - 1, mid, guess_item, guess_for;
while (low <= high) {
mid = Math.floor((low + high) / 2);
guess_item = arr[mid];
guess_for = get_comparable(guess_item);
if (guess_for === search_for) {
arr.splice(mid, 0, item);
return;
} else if (guess_for > search_for) {
high = mid - 1;
} else {
low = mid + 1;
}
}
arr.splice(low, 0, item);
}
export { binary_insert, binary_insert_unique, binary_insert_with, binary_search, binary_search_with, deduped, equals, includes_same_members, mutate_filter, pick_random, pick_random_excliding_one, random_iterate, remove, wrap };

@@ -1,2 +0,99 @@

export { RGB, RGBA, hex_to_rgb, hex_to_rgba, rgb_int, rgb_int_to_rgb, rgb_to_hex, rgb_to_rgba, rgb_to_rgba_int, rgb_to_string, rgb_value, rgba_int, rgba_int_to_rgba, rgba_to_hex, rgba_to_string } from '../chunk/G5UKFL7F.js';
import '../chunk/5ZKAE4VZ.js';
class RGB {
/**
* Creates an instance of the RGB class.
* @param r - The red component of the RGB color.
* @param g - The green component of the RGB color.
* @param b - The blue component of the RGB color.
*/
constructor(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
}
/**
* Returns a string representation of the RGB color in the format "rgb(r g b)".
*/
toString = rgb_to_string.bind(null, this);
}
class RGBA extends RGB {
/**
* Creates an instance of the RGBA class.
* @param r - The red component of the RGBA color.
* @param g - The green component of the RGBA color.
* @param b - The blue component of the RGBA color.
* @param a - The alpha component (opacity) of the RGBA color.
*/
constructor(r, g, b, a) {
super(r, g, b);
this.a = a;
}
/**
* Returns a string representation of the RGBA color in the format "rgb(r g b / a)".
*/
toString = rgba_to_string.bind(null, this);
}
function rgb_to_string(rgb) {
return `rgb(${rgb.r} ${rgb.g} ${rgb.b})`;
}
function rgba_to_string(rgba) {
return `rgb(${rgba.r} ${rgba.g} ${rgba.b} / ${rgba.a})`;
}
function rgb_to_rgba(rgb, a) {
return new RGBA(rgb.r, rgb.g, rgb.b, a);
}
function rgb_int(rgb) {
return rgb.r << 16 | rgb.g << 8 | rgb.b;
}
function rgb_int_to_rgb(value) {
return new RGB(value >> 16 & 255, value >> 8 & 255, value & 255);
}
function rgba_int(rgba) {
return rgba.r << 24 | rgba.g << 16 | rgba.b << 8 | rgba.a;
}
function rgba_int_to_rgba(value) {
return new RGBA(value >> 24 & 255, value >> 16 & 255, value >> 8 & 255, value & 255);
}
function rgb_to_rgba_int(rgb, a) {
return rgb_int(rgb) << 8 | a;
}
function rgb_value(rgb) {
return `${rgb.r} ${rgb.g} ${rgb.b}`;
}
function rgb_to_hex(rgb) {
return "#" + rgb.r.toString(16) + rgb.g.toString(16) + rgb.b.toString(16);
}
function rgba_to_hex(rgba) {
return "#" + rgba.r.toString(16) + rgba.g.toString(16) + rgba.b.toString(16) + rgba.a.toString(16);
}
function hex_to_rgb(hex) {
if (hex[0] === "#")
hex = hex.slice(1);
if (hex.length < 6) {
const r2 = parseInt(hex[0], 16);
const g2 = parseInt(hex[1], 16);
const b2 = parseInt(hex[2], 16);
return new RGB(r2, g2, b2);
}
const r = parseInt(hex.slice(0, 2), 16);
const g = parseInt(hex.slice(2, 4), 16);
const b = parseInt(hex.slice(4, 6), 16);
return new RGB(r, g, b);
}
function hex_to_rgba(hex) {
if (hex[0] === "#")
hex = hex.slice(1);
if (hex.length < 6) {
const r2 = parseInt(hex[0], 16);
const g2 = parseInt(hex[1], 16);
const b2 = parseInt(hex[2], 16);
const a2 = hex[3] ? parseInt(hex[3], 16) / 255 : 1;
return new RGBA(r2, g2, b2, a2);
}
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
const a = hex.length > 7 ? parseInt(hex.slice(7, 9), 16) / 255 : 1;
return new RGBA(r, g, b, a);
}
export { RGB, RGBA, hex_to_rgb, hex_to_rgba, rgb_int, rgb_int_to_rgb, rgb_to_hex, rgb_to_rgba, rgb_to_rgba_int, rgb_to_string, rgb_value, rgba_int, rgba_int_to_rgba, rgba_to_hex, rgba_to_string };

@@ -1,2 +0,135 @@

export { in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quart, in_out_quint, in_out_sine, in_quad, in_quart, in_quint, in_qut_quad, in_sine, linear, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sine } from '../chunk/P77FFUTD.js';
import '../chunk/5ZKAE4VZ.js';
function linear(t) {
return t;
}
function in_sine(t) {
return -1 * Math.cos(t * (Math.PI / 2)) + 1;
}
function out_sine(t) {
return Math.sin(t * (Math.PI / 2));
}
function in_out_sine(t) {
return -0.5 * (Math.cos(Math.PI * t) - 1);
}
function in_quad(t) {
return t * t;
}
function out_quad(t) {
return t * (2 - t);
}
function in_qut_quad(t) {
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}
function in_cubic(t) {
return t * t * t;
}
function out_cubic(t) {
const t1 = t - 1;
return t1 * t1 * t1 + 1;
}
function in_out_cubic(t) {
return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
}
function in_quart(t) {
return t * t * t * t;
}
function out_quart(t) {
const a = t - 1;
return 1 - a * a * a * a;
}
function in_out_quart(t) {
const a = t - 1;
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * a * a * a * a;
}
function in_quint(t) {
return t * t * t * t * t;
}
function out_quint(t) {
const a = t - 1;
return 1 + a * a * a * a * a;
}
function in_out_quint(t) {
const a = t - 1;
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * a * a * a * a * a;
}
function in_expo(t) {
if (t === 0) {
return 0;
}
return Math.pow(2, 10 * (t - 1));
}
function out_expo(t) {
return t === 1 ? 1 : -Math.pow(2, -10 * t) + 1;
}
function in_out_expo(t) {
if (t === 0 || t === 1)
return t;
const a = t * 2, b = a - 1;
return a < 1 ? 0.5 * Math.pow(2, 10 * b) : 0.5 * (-Math.pow(2, -10 * b) + 2);
}
function in_circ(t) {
const a = t / 1;
return -1 * (Math.sqrt(1 - a * t) - 1);
}
function out_circ(t) {
const a = t - 1;
return Math.sqrt(1 - a * a);
}
function in_out_circ(t) {
const a = t * 2, b = a - 2;
return a < 1 ? -0.5 * (Math.sqrt(1 - a * a) - 1) : 0.5 * (Math.sqrt(1 - b * b) + 1);
}
function in_back(t, magnitude = 1.70158) {
return t * t * ((magnitude + 1) * t - magnitude);
}
function out_back(t, magnitude = 1.70158) {
const a = t / 1 - 1;
return a * a * ((magnitude + 1) * a + magnitude) + 1;
}
function in_out_back(t, magnitude = 1.70158) {
const a = t * 2, b = a - 2, s = magnitude * 1.525;
return a < 1 ? 0.5 * a * a * ((s + 1) * a - s) : 0.5 * (b * b * ((s + 1) * b + s) + 2);
}
function in_elastic(t, magnitude = 0.7) {
if (t === 0 || t === 1)
return t;
const a = t / 1, b = a - 1, p = 1 - magnitude, s = p / (2 * Math.PI) * Math.asin(1);
return -(Math.pow(2, 10 * b) * Math.sin((b - s) * (2 * Math.PI) / p));
}
function out_elastic(t, magnitude = 0.7) {
const p = 1 - magnitude, a = t * 2;
if (t === 0 || t === 1)
return t;
const s = p / (2 * Math.PI) * Math.asin(1);
return Math.pow(2, -10 * a) * Math.sin((a - s) * (2 * Math.PI) / p) + 1;
}
function in_out_elastic(t, magnitude = 0.7) {
const p = 1 - magnitude;
if (t === 0 || t === 1)
return t;
const a = t * 2, b = a - 1, s = p / (2 * Math.PI) * Math.asin(1);
return a < 1 ? -0.5 * (Math.pow(2, 10 * b) * Math.sin((b - s) * (2 * Math.PI) / p)) : Math.pow(2, -10 * b) * Math.sin((b - s) * (2 * Math.PI) / p) * 0.5 + 1;
}
function out_bounce(t) {
const a = t / 1;
if (a < 1 / 2.75) {
return 7.5625 * a * a;
}
if (a < 2 / 2.75) {
const b2 = a - 1.5 / 2.75;
return 7.5625 * b2 * b2 + 0.75;
}
if (a < 2.5 / 2.75) {
const b2 = a - 2.25 / 2.75;
return 7.5625 * b2 * b2 + 0.9375;
}
const b = a - 2.625 / 2.75;
return 7.5625 * b * b + 0.984375;
}
function in_bounce(t) {
return 1 - out_bounce(1 - t);
}
function in_out_bounce(t) {
return t < 0.5 ? in_bounce(t * 2) * 0.5 : out_bounce(t * 2 - 1) * 0.5 + 0.5;
}
export { in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quart, in_out_quint, in_out_sine, in_quad, in_quart, in_quint, in_qut_quad, in_sine, linear, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sine };

22

dist/index/index.js

@@ -1,8 +0,14 @@

export { array_exports as array } from '../chunk/7MSPXAUH.js';
export { color_exports as color } from '../chunk/G5UKFL7F.js';
export { ease_exports as ease } from '../chunk/P77FFUTD.js';
export { math_exports as math } from '../chunk/XW2K5NBP.js';
export { misc_exports as misc } from '../chunk/HKPIYLA2.js';
export { trig_exports as trig } from '../chunk/IUUNWCGK.js';
import '../chunk/5ZKAE4VZ.js';
export { types_exports as types } from '../chunk/QR25BPRP.js';
import * as array from './array';
export { array };
import * as color from './color';
export { color };
import * as ease from './ease';
export { ease };
import * as math from './math';
export { math };
import * as misc from './misc';
export { misc };
import * as trig from './trig';
export { trig };
import * as types from './types';
export { types };

@@ -1,2 +0,28 @@

export { between, bounce, clamp, map_range, number_equals, random, random_from, random_int, random_int_from, ranges_intersecting, remainder, to_percent, wrap } from '../chunk/XW2K5NBP.js';
import '../chunk/5ZKAE4VZ.js';
const random = (max) => Math.random() * max;
const random_from = (min, max) => Math.random() * (max - min) + min;
const random_int = (max) => Math.floor(Math.random() * max);
const random_int_from = (min, max) => Math.floor(Math.random() * (max - min)) + min;
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
const remainder = (a, b) => (a % b + b) % b;
const wrap = (value, min, max) => remainder(value - min, max - min) + min;
const bounce = (value, min, max) => {
const range = max - min, rem = wrap(value - min, 0, 2 * range), distance = Math.abs(rem - range);
return max - distance;
};
const map_range = (value, in_min, in_max, out_min, out_max) => (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
const to_percent = (value, min, max) => (value - min) / (max - min);
const number_equals = (a, b) => Math.abs(a - b) < Number.EPSILON;
const between = (a, b, c) => {
if (a > c)
[a, c] = [c, a];
return a - Number.EPSILON <= b && b <= c + Number.EPSILON;
};
const ranges_intersecting = (a1, b1, a2, b2) => {
if (a1 > b1)
[a1, b1] = [b1, a1];
if (a2 > b2)
[a2, b2] = [b2, a2];
return a1 <= b2 && a2 <= b1;
};
export { between, bounce, clamp, map_range, number_equals, random, random_from, random_int, random_int_from, ranges_intersecting, remainder, to_percent, wrap };

@@ -1,2 +0,25 @@

export { chain, entries, false_fn, is_non_nullable, is_of_class, is_plain_object, keys, noop, reverse_chain, true_fn, xor } from '../chunk/HKPIYLA2.js';
import '../chunk/5ZKAE4VZ.js';
const noop = () => void 0;
const true_fn = () => true;
const false_fn = () => false;
const xor = (a, b) => a ? !b : b;
const entries = Object.entries;
const keys = Object.keys;
const is_plain_object = (value) => value && Object.getPrototypeOf(value) === Object.prototype;
const is_of_class = (v, c) => v instanceof c || v && v.constructor === c;
const is_non_nullable = (i) => i != null;
function chain(callbacks) {
return (...args) => {
for (const callback of callbacks)
callback && callback(...args);
};
}
function reverse_chain(callbacks) {
return (...args) => {
for (let i = callbacks.length - 1; i >= 0; i--) {
const callback = callbacks[i];
callback && callback(...args);
}
};
}
export { chain, entries, false_fn, is_non_nullable, is_of_class, is_plain_object, keys, noop, reverse_chain, true_fn, xor };

@@ -1,2 +0,126 @@

export { Force, Vector, ZERO, force, force_to_vector, vector, vector_add, vector_angle, vector_difference, vector_distance, vector_divide, vector_equals, vector_multiply, vector_product, vector_quotient, vector_rotate, vector_rotate_around, vector_subtract, vector_sum, zero } from '../chunk/IUUNWCGK.js';
import '../chunk/5ZKAE4VZ.js';
class Vector {
x;
y;
constructor(x, y) {
if (typeof x === "string") {
const [xStr, yStr] = x.slice(1, -1).split(", ");
x = Number(xStr);
y = Number(yStr);
} else if (typeof x === "object") {
y = x.y;
x = x.x;
}
this.x = x;
this.y = y ?? x;
}
*[Symbol.iterator]() {
yield this.x;
yield this.y;
}
toString() {
return `(${this.x}, ${this.y})`;
}
toJSON() {
return { x: this.x, y: this.y };
}
}
const vector = (...args) => new Vector(...args);
const ZERO = vector(0, 0);
const zero = () => vector(0, 0);
function vector_equals(a, b) {
return a.x === b.x && a.y === b.y;
}
function vector_subtract(a, b) {
a.x -= b.x;
a.y -= b.y;
}
function vector_difference(a, b) {
return vector(a.x - b.x, a.y - b.y);
}
function vector_add(vec, x, y) {
if (typeof x === "number") {
vec.x += x;
vec.y += y ?? x;
return;
}
if (x instanceof Force) {
x = force_to_vector(x);
}
vec.x += x.x;
vec.y += x.y;
}
function vector_sum(a, b) {
return vector(a.x + b.x, a.y + b.y);
}
function vector_multiply(a, b) {
if (typeof b === "number") {
a.x *= b;
a.y *= b;
return;
}
a.x *= b.x;
a.y *= b.y;
}
function vector_product(a, b) {
return vector(a.x * b.x, a.y * b.y);
}
function vector_divide(a, b) {
a.x /= b.x;
a.y /= b.y;
}
function vector_quotient(a, b) {
return vector(a.x / b.x, a.y / b.y);
}
function vector_distance(a, b) {
const x = a.x - b.x;
const y = a.y - b.y;
return Math.sqrt(x * x + y * y);
}
function vector_angle(a, b) {
return Math.atan2(b.y - a.y, b.x - a.x);
}
function vector_rotate(point, rad) {
const { x, y } = point, cos = Math.cos(rad), sin = Math.sin(rad);
point.x = x * cos - y * sin;
point.y = x * sin + y * cos;
}
function vector_rotate_around(point, origin, rad) {
const { x, y } = point, { x: ox, y: oy } = origin, cos = Math.cos(rad), sin = Math.sin(rad);
point.x = ox + (x - ox) * cos - (y - oy) * sin;
point.y = oy + (x - ox) * sin + (y - oy) * cos;
}
class Force {
/**
* The magnitude of the force.
*/
distance;
/**
* The angle of the force in radians.
*/
angle;
constructor(a, b) {
if (typeof a === "object") {
this.angle = vector_angle(a, b);
this.distance = vector_distance(a, b);
} else {
this.distance = a;
this.angle = b;
}
}
*[Symbol.iterator]() {
yield this.distance;
yield this.angle;
}
}
const force = (...args) => new Force(...args);
function force_to_vector(distance, angle) {
if (typeof distance === "object") {
angle = distance.angle;
distance = distance.distance;
}
const x = distance * Math.cos(angle);
const y = distance * Math.sin(angle);
return vector(x, y);
}
export { Force, Vector, ZERO, force, force_to_vector, vector, vector_add, vector_angle, vector_difference, vector_distance, vector_divide, vector_equals, vector_multiply, vector_product, vector_quotient, vector_rotate, vector_rotate_around, vector_subtract, vector_sum, zero };

@@ -1,1 +0,1 @@

import '../chunk/QR25BPRP.js';
{
"name": "@nothing-but/utils",
"version": "0.4.0",
"version": "0.4.1",
"license": "MIT",

@@ -101,8 +101,7 @@ "author": "Damian Tarnawski <gthetarnav@gmail.com>",

"scripts": {
"dev": "tsup --watch",
"build": "tsup",
"prepublish": "pnpm build",
"test": "vitest",
"test": "vitest -c ../../configs/vitest.config.js",
"typecheck": "tsc --noEmit"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc