
Security News
/Research
npm Phishing Email Targets Developers with Typosquatted Domain
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.
bme-utils is a TypeScript library for utilities required for your next daily projects.
Use the package manager npm or yarn to install bme-utils.
npm i bme-utils
yarn add bme-utis
Returns trimmed value from the provided range. If the minimum value will be larger than the maximum value function will throw an error.
import { clamp } from 'bme-utils';
clamp(8, 21, 66); // 21 — min
clamp(88, 21, 66); // 88 — max
clamp(37, 21, 66); // 37 — value
Where:
value
is value to be clampedmin
is minimum allowed valuemax
is maximum allowed valueReturns boolean results of comparing two objects. It simply compares JSONed objects. Values can be in any format that can be transformed to JSON string.
import { compareObjects } from 'bme-utils';
const objectA = { manufacturer: 'Mercedes-Benz', model: 'A-Class', engine: 'A45s' };
const objectB = { manufacturer: 'Mercedes-Benz', model: 'A-Class', engine: 'A200' };
compareObjects(objectA, objectB); // false
compareObjects(objectA, objectA); // true
compareObjects(objectA, { manufacturer: 'Mercedes-Benz', model: 'A-Class', engine: 'A45s' }); // true
Where:
objectA
is any value (Preferred: object)objectB
is any value (Preferred: object)WORK IN PROGRESS, DEFAULT VALUES MIGHT CHANGE IN FUTURE Debounce function allows to "group" calls in time sequences to execute it only once. Imagine that you are in the elevator where doors are closing. When someone from the outside press the button it will open doors and the elevator would not go up until doors are closed.
import { debounce } from 'bme-utils';
const callback = () => console.debug('Hello world');
const wait = 450;
debounce(callback, wait); // 'Hello world
Where:
callback
is functionwait
is value in millisecond to wait until execute code (or start elevator) (Default: 450)Returns device type. It can be used to detect if the user is using mobile device or desktop.
import { detectDevice } from 'bme-utils';
detectDevice();
export type DeviceType = 'desktop' | 'mobile' | 'tablet';
export type Browser = 'Chrome' | 'Firefox' | 'Safari' | 'Edge' | 'IE' | 'unknown';
export type OS = 'iOS' | 'Android' | 'Windows' | 'macOS' | 'Linux' | 'unknown';
interface Response {
type: DeviceType;
browser: Browser;
os: OS
}
Returns the first element of an array or null value. Might be useful if you enforce the no magic numbers rule.
import { firstElement } from 'bme-utils';
const list = ['First', 'Second', 'Third'];
const listB = [];
firstElement(list); // 'First'
firstElement(listB); // null
Returns the last element of an array or null value. Might be useful if you enforce the no magic numbers rule.
import { lastElement } from 'bme-utils';
const list = ['First', 'Second', 'Third'];
const listB = [];
lastElement(list); // 'Third'
lastElement(listB); // null
Where:
list
is array of anyReturns a boolean value. The input value can be an array of any, string, number, object, null or undefined. For array and object, it checks if there's more than or equal to 1 entry. For string, it checks if there's more than or equal to 1 character. For number, it checks if it's not equal to NaN or 0. For null and undefined it always returns false.
import { isEmpty } from 'bme-utils';
const value = ['First', 'Second', 'Third'];
const valueB = [];
const valueC = 0;
const valueD = 100;
const valueE = NaN;
const valueF = 'First';
const valueG = '';
const valueH = {};
const valueI = { manufacturer: 'Mercedes-Benz' };
isEmpty(value); // false
isEmpty(valueB); // true
isEmpty(valueC); // true
isEmpty(valueD); // false
isEmpty(valueE); // true
isEmpty(valueF); // false
isEmpty(valueG); // true
isEmpty(valueH); // true
isEmpty(valueI); // false
Where:
value
is array of any, string, number, object, null or undefinedReturns a maximum index value. The input value can be an array of any or string. For array it will return last element index and for string it will return last letter index. If input will be empty it will return null.
import { maxIndex } from 'bme-utils';
const elements = ['First', 'Second', 'Third'];
const elementsB = [];
const elementsC = 'First';
const elementsD = '';
maxIndex(elements); // 2
maxIndex(elementsB); // null
maxIndex(elementsC); // 4
maxIndex(elementsD); // null
Where:
elements
is array of any or string.Returns a random boolean value. Optionally you can set trueChance.
import { randomBoolean } from 'bme-utils';
const trueChance = 0.66;
randomBoolean(trueChance); // true | false
Where:
trueChance
is an optional number value in the range of 0 to 1. (Default: 0.5)Returns a random element of array. The input value can be an array of any. If array will be empty it will return null.
import { randomElement } from 'bme-utils';
const elements = ['First', 'Second', 'Third'];
const elementsB = [];
maxIndex(elements); // 2
maxIndex(elementsB); // null
Where:
elements
is array of any or string.Returns a random number value from provided range values. The minimum value is set to 0 by default.
import { randomNumber } from 'bme-utils';
const max = 100;
const min = 66;
randomNumber(max, min); // number
Where:
max
is a maximum valuemin
is an optional minimum value. (Default: 0)EXPERIMENTAL Transform RGB or hex value to RGBA value.
import { toRgba } from 'bme-utils';
const colour = '#300032';
const colourB = 'rgb(48, 0, 50)';
const opacity = 0.33;
toRgba(colour, opacity); // rgba(48, 0, 50, 0.33)
toRgba(colourB, opacity); // rgba(48, 0, 50, 0.33)
Where:
colour
is a string value with HEX or RGB colouropacity
is a number value of demanded opacityPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
FAQs
Utilities for Node.JS, JavaScript and TypeScript projects
The npm package bme-utils receives a total of 2 weekly downloads. As such, bme-utils popularity was classified as not popular.
We found that bme-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.
Security News
Knip hits 500 releases with v5.62.0, refining TypeScript config detection and updating plugins as monthly npm downloads approach 12M.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.