Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rjweb/utils

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rjweb/utils - npm Package Compare versions

Comparing version 1.12.17 to 1.12.18

32

lib/cjs/array.js

@@ -34,2 +34,4 @@ "use strict";

limit: () => limit,
median: () => median,
mode: () => mode,
random: () => random,

@@ -45,4 +47,4 @@ randomCrypto: () => randomCrypto,

var number = __toESM(require("./number"));
function remove(input, mode, value) {
switch (mode) {
function remove(input, mode2, value) {
switch (mode2) {
case "index": {

@@ -76,2 +78,26 @@ const val = value;

}
function median(input) {
const sorted = input.sort((a, b) => a - b);
const mid = Math.floor(sorted.length / 2);
if (sorted.length % 2 === 0) {
return (sorted[mid - 1] + sorted[mid]) / 2;
} else {
return sorted[mid];
}
}
function mode(input) {
const count = /* @__PURE__ */ new Map();
for (const num of input) {
count.set(num, (count.get(num) ?? 0) + 1);
}
let max = 0;
let mode2 = 0;
for (const [key, value] of count) {
if (value > max) {
max = value;
mode2 = key;
}
}
return mode2;
}
function sum(input) {

@@ -141,2 +167,4 @@ let sum2 = 0;

limit,
median,
mode,
random,

@@ -143,0 +171,0 @@ randomCrypto,

@@ -35,2 +35,3 @@ "use strict";

prime: () => prime,
reduce: () => reduce,
round: () => round,

@@ -76,3 +77,7 @@ triangle: () => triangle

return 1;
return input * factorial(input - 1);
let result = 1;
for (let i = 2; i <= input; i++) {
result *= i;
}
return result;
}

@@ -91,6 +96,16 @@ function between(input, min, max) {

}
const fibonacciCache = /* @__PURE__ */ new Map();
function fibonacci(input) {
if (input <= 1)
return input;
return fibonacci(input - 1) + fibonacci(input - 2);
if (input === 1)
return 1;
else if (input <= 0)
return 0;
if (fibonacciCache.has(input))
return fibonacciCache.get(input);
const sequence = [0, 1];
for (let i = 2; i <= input; i++) {
sequence[i] = sequence[i - 1] + sequence[i - 2];
}
fibonacciCache.set(input, sequence[input]);
return sequence[input];
}

@@ -124,2 +139,6 @@ function triangle(input) {

}
function reduce(numerator, denominator) {
const _gcd = gcd(numerator, denominator);
return [numerator / _gcd, denominator / _gcd];
}
// Annotate the CommonJS export names for ESM import in node:

@@ -141,4 +160,5 @@ 0 && (module.exports = {

prime,
reduce,
round,
triangle
});

2

lib/cjs/pckg.json
{
"name": "@rjweb/utils",
"version": "1.12.17",
"version": "1.12.18",
"description": "Easy and Lightweight Utilities",

@@ -5,0 +5,0 @@ "module": "lib/esm/index.js",

import * as number from "./number";
function remove(input, mode, value) {
switch (mode) {
function remove(input, mode2, value) {
switch (mode2) {
case "index": {

@@ -32,2 +32,26 @@ const val = value;

}
function median(input) {
const sorted = input.sort((a, b) => a - b);
const mid = Math.floor(sorted.length / 2);
if (sorted.length % 2 === 0) {
return (sorted[mid - 1] + sorted[mid]) / 2;
} else {
return sorted[mid];
}
}
function mode(input) {
const count = /* @__PURE__ */ new Map();
for (const num of input) {
count.set(num, (count.get(num) ?? 0) + 1);
}
let max = 0;
let mode2 = 0;
for (const [key, value] of count) {
if (value > max) {
max = value;
mode2 = key;
}
}
return mode2;
}
function sum(input) {

@@ -96,2 +120,4 @@ let sum2 = 0;

limit,
median,
mode,
random,

@@ -98,0 +124,0 @@ randomCrypto,

@@ -37,3 +37,7 @@ function generate(min, max) {

return 1;
return input * factorial(input - 1);
let result = 1;
for (let i = 2; i <= input; i++) {
result *= i;
}
return result;
}

@@ -52,6 +56,16 @@ function between(input, min, max) {

}
const fibonacciCache = /* @__PURE__ */ new Map();
function fibonacci(input) {
if (input <= 1)
return input;
return fibonacci(input - 1) + fibonacci(input - 2);
if (input === 1)
return 1;
else if (input <= 0)
return 0;
if (fibonacciCache.has(input))
return fibonacciCache.get(input);
const sequence = [0, 1];
for (let i = 2; i <= input; i++) {
sequence[i] = sequence[i - 1] + sequence[i - 2];
}
fibonacciCache.set(input, sequence[input]);
return sequence[input];
}

@@ -85,2 +99,6 @@ function triangle(input) {

}
function reduce(numerator, denominator) {
const _gcd = gcd(numerator, denominator);
return [numerator / _gcd, denominator / _gcd];
}
export {

@@ -101,4 +119,5 @@ between,

prime,
reduce,
round,
triangle
};
{
"name": "@rjweb/utils",
"version": "1.12.17",
"version": "1.12.18",
"description": "Easy and Lightweight Utilities",

@@ -5,0 +5,0 @@ "module": "lib/esm/index.js",

@@ -43,2 +43,28 @@ /**

/**
* Get the Median of all Numbers in an Array
* @example
* ```
* import { array } from "@rjweb/utils"
*
* const arr = [4, 65, 76, 90, 1, -3]
*
* array.median(arr) // 35
* ```
* @since 1.12.18
* @supports nodejs, browser
*/ export declare function median(input: number[]): number;
/**
* Get the Mode of all Numbers in an Array
* @example
* ```
* import { array } from "@rjweb/utils"
*
* const arr = [4, 65, 76, 90, 1, -3, 4, 4, 65, 65]
*
* array.mode(arr) // 4
* ```
* @since 1.12.18
* @supports nodejs, browser
*/ export declare function mode(input: number[]): number;
/**
* Get the Sum of Numbers in an Array

@@ -45,0 +71,0 @@ * @example

@@ -193,1 +193,13 @@ /**

*/ export declare function power(input: number, power: number): boolean;
/**
* Reduce a fraction to its simplest form
* @example
* ```
* import { number } from "@rjweb/utils"
*
* number.reduce(5, 10) // [1, 2]
* number.reduce(10, 15) // [2, 3]
* ```
* @since 1.12.18
* @supports nodejs, browser
*/ export declare function reduce(numerator: number, denominator: number): [number, number];
{
"name": "@rjweb/utils",
"version": "1.12.17",
"version": "1.12.18",
"description": "Easy and Lightweight Utilities",

@@ -5,0 +5,0 @@ "module": "lib/esm/index.js",

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