
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
@rashedmakkouk/dev-utils
Advanced tools
Utility library.
Install package in your project.
# NPM
npm install @rashedmakkouk/dev-utils
# Yarn
yarn add @rashedmakkouk/dev-utils
import { module } from '@rashedmakkouk/dev-utils';
module();
const { module } = require('@rashedmakkouk/dev-utils');
module();
autolinksParses a text string and returns links matching:
Builds on autolinker with custom configuration and output.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | No | '' | Text to parse. |
(Object.links): Array list of unique words links (e.g. mention, hashtag, url).(Object.matches): Array list of all matched links metadata.autolinks('The #quick brown @fox.');
// =>
// {
// "links": [
// "#quick",
// "@fox"
// ],
// "matches": [
// {
// "__jsduckDummyDocProp": null,
// "matchedText": "#quick",
// "offset": 4,
// "tagBuilder": {
// "newWindow": true,
// "truncate": {
// "length": null,
// "location": "end"
// },
// "className": ""
// },
// "serviceName": "twitter",
// "hashtag": "quick"
// },
// {
// "__jsduckDummyDocProp": null,
// "matchedText": "@fox",
// "offset": 17,
// "tagBuilder": {
// "newWindow": true,
// "truncate": {
// "length": null,
// "location": "end"
// },
// "className": ""
// },
// "serviceName": "twitter",
// "mention": "fox"
// }
// ]
// }
delayPromise
Delays executions of a specified piece of code.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
ms | number | Yes | - | Duration to delay in milliseconds. |
race | boolean | No | false | If true, returns a Promise object that is rejected with status 408 Request Timeout. |
(Object): Returns Promise Object.delay(1000, true);
escapeSQL input data escape and format for MySQL.
A sqlstring wrapper for convenience.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
value | Any | Yes | - | Data to escape. |
options | object | No | - | Custom options to apply. |
options.escapeId | boolean | No | false | Escapes Identifiers such as database table column names and reserved words. |
options.parseInteger | boolean | No | false | Parses values such as LIMIT and OFFSET. |
options.stripQuote | boolean | No | false | Removes quotes from result; useful for RegExp or query conditions e.g. ASC. |
(string): Returns escaped string.escape('abc', { stripQuote: true });
// => abc
initialsExtracts the first character from the first and last words in a string.
Splits at: Splits at: white space, comma, dot, pipe, underscore, dash.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | No | '' | Text to extract characters from. |
(string): Returns extracted characters as string.initials('John Unknown-Doe');
// => JD
isBase64Validates if supplied mime type and/or base64 string are valid.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
value | string | Yes | - | Base64 value. |
options | object | No | - | Custom options to apply. |
options.allowEmpty | boolean | No | false | Returns true if value is empty. |
options.allowMime | boolean | No | false | String may include mime type. |
options.mimeRequired | boolean | No | false | String should include mime type. |
options.urlSafe | boolean | No | false | See Base64URL. |
(boolean): Returns true if supplied string passes checks, else false.isBase64('data:image/png;base64,<code>', { mimeRequired: true });
// => true
isValidVerifies if supplied payload is valid by defined type.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
isTypeof | string | Yes | - | string, array, number, object, jsonStr. |
value | Any | No | - | Data to validate. |
options | object | No | - | Custom options to apply. |
options.allowEmpty | boolean | No | false | If true, validates empty, 0, null and undefined values as valid. |
(boolean): Returns true if supplied payload passes checks, else false.isValid('string', 'undefined');
// => false
isValid('string', '', { allowEmpty: true });
// => true
isValid('number', 'abc');
// => false
isValid('number', '123');
// => false
isValid('number', 0);
// => false
isValid('object', ['abc']);
// => false
isValid('object', {}, { allowEmpty: true });
// => true
joinPathJoins list of absolute and relative paths as a string.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
segments | Array | Yes | - | List of paths to join. |
options | object | No | - | Custom options to apply. |
options.resolve | boolean | No | false | If true, tries to resolve segments into an absolute path. |
(string): Returns joined path string.joinPath(['/foo', 'bar', 'baz\\abc', './def', '..']);
// => '/foo/bar/baz/abc'
letterCaseFormats supplied string to defined case.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | Yes | - | Text to format. |
options | object | Yes | - | Custom options to apply. |
options.letterCase | string | Yes | - | lower, upper, sentence, kebab, title. |
options.separators | Array | No | - | Replaces specified symbols with white space. |
(string): Returns formatted string.letterCase('_the quiCK--brown FOx_!', { letterCase: 'sentence' });
// => '_The quick--brown fox_!'
letterCase('the #quiCK brown FOx!', { letterCase: 'kebab' });
// => 'the-quick-brown-fox'
// Applies custom separators if supplied, else defaults to: [_-\s]+
letterCase('_the quiCK--brown FOx_!', { letterCase: 'title' });
// => 'The Quick Brown Fox!'
msParses a number representation or a string time period (e.g. 1h, 2d) to Unix Timestamp.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
span | string | number | Yes | - | d, h, m, ms, s, w, y. |
(number): Returns time representation in seconds, else parses value as integer.ms('1hr');
// => 3600
ms('1000');
// => 1000
normalizeNormalizes payload by defined object attribute.
Payload data needs to be consistent and has similar data structure to avoid unexpected results, specifically defined
idAttribute(e.g. results from a database query).
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
key | string | Yes | - | Object property name to move records to. |
payload | Array | object | Yes | - | Data to normalize. |
options | object | No | - | Custom options to apply. |
options.idAttribute | string | No | id | Object property name to normalize records based on. |
(Object.entities): Normalized data objects.(Object.result): List of data idAttributes.// Array payload.
normalize('posts', [{ id: 1, title: 'abc' }, { id: 2, title: 'def' }], { idAttribute: 'uid' });
// =>
// {
// entities: {
// posts: {
// 1: { uid: 1, title: 'abc' },
// 2: { uid: 2, title: 'def' }
// },
// },
// result: [1,2]
// }
// Object payload.
normalize('posts', { id: 1, title: 'abc' });
// =>
// {
// entities: {
// posts: {
// 1: { id: 1, title: 'abc' }
// },
// },
// result: 1
// }
parseUrlParses URL string segments including query string values, if any.
A url-parse wrapper for convenience.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes | - | URL to parse. |
(Object): Returns parsed URL object.parseUrl('https://localhost:8000/foo/bar?firstName=John&lastName=Doe');
// =>
// {
// "slashes": true,
// "protocol": "https:",
// "hash": "",
// "query": {
// "firstName": "John",
// "lastName": "Doe"
// },
// "pathname": "/foo/bar",
// "auth": "",
// "host": "localhost:8000",
// "port": "8000",
// "hostname": "localhost",
// "password": "",
// "username": "",
// "origin": "https://localhost:8000",
// "href": "https://localhost:8000/foo/bar?firstName=John&lastName=Doe"
// }
randomGenerates a random string with customizable options.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
type | string | Yes | - | filename, number, title, temp, uuid. |
options | object | No | - | Custom options to apply. |
options.min | number | No | 0 | If type is number, minimum value to start from. |
options.max | number | No | 1 | If type is number, maximum value to end at. |
options.prefix | string | No | - | Text to add to the beginning of the result. |
options.suffix | string | No | - | Text to add to the end of the result. |
(string|number): Returns generated string or number.random('filename', { prefix: 'post' });
// => post_2018-01-01_12-00-00_7f2a79ba-962e-4b35-96d0-28xf1d025107
random('number', { min: 1000, max: 2000 });
// => 1784
random('title', { prefix: 'post' });
// => post_2018-01-01_12-00-00
random('temp');
// => 2018-01-01_12-00-00_efc7438f-0a4d-4538-af87-b6984xe04688
random('uuid');
// => 7e0ea78d-c170-4449-93fb-f5caxb952752
sanitizeTrims white spaces and removes HTML tags.
Uses: trimWhitespace
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | Yes | - | Text to trim. |
(string): Returns sanitized string.sanitize('<script>"the__ #quicK-- BROWN @foX_".js</script> <html><div>Html code</div></html>');
// => "the__ #quicK-- BROWN @foX_".js Html code
singularTrims last character if ends with s or replaces ies with y.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | Yes | - | Text to convert. |
(string): Returns trimmed text.singular('posts');
// => post
singular('commodities');
// => commodity
singular({ key: 'posts' });
// => ''
splitArraySplits any array to chunks by supplied size.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
array | Array | Yes | - | Data array to split. |
size | number | No | - | Size of each array chunk; bypasses split if empty. |
(Array): Returns new array chunks.splitArray([{ id: 1, title: 'abc' }, { id: 2, title: 'def' }]);
// =>
// [
// { "id": 1, "title": "name1" },
// { "id": 2, "title": "name2" }
// ]
splitArray([{ id: 1, title: 'abc' }, { id: 2, title: 'def' }], 1);
// =>
// [
// [{ "id": 1, "title": "name1" }],
// [{ "id": 2, "title": "name2" }]
// ]
timestampParses any date value to a timestamp with predefined or custom format.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
date | string | number | object | Yes | - | Date string, Date object, Unix Timestamp. |
options | object | No | - | Custom options to apply. |
options.format | string | No | DD/MM/YYYY | datetime, fromNow, short, sql, Moment. |
(string): Returns formatted timestamp.timestamp(Date.now());
// => 31/12/2018
timestamp(new Date('12/31/2018'), { format: 'datetime' });
// => Monday, December 31 at 12:00AM
timestamp(Date(), { format: 'fromNow' });
// => a few seconds ago
timestamp(moment('12/31/2018'), { format: 'short' });
// => Mon, Dec 31 12:00AM
timestamp('12/31/2018 12:00', { format: 'sql' });
// => 2018-12-31 12:00:00
toArrayConverts any value to array.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
value | Any | Yes | - | Data to convert. |
options | object | No | - | Custom options to apply. |
options.separator | string | No | , | The pattern where the split should occur. |
options.toNumber | boolean | No | false | If true, maps array values as Number. |
(Array): Returns array based on supplied params.toArray('1', { toNumber: true });
// => [1]
toArray(['a', 'b', 'c']);
// => ['a', 'b', 'c']
toArray({ id: 1, title: 'name1' });
// => [{ id: 1, title: 'name1' }]
toArray('1,2,3');
// => ['1', '2', '3']
toArray(' a-2-3 -', { toNumber: true, separator: '-' });
// => [NaN, 2, 3]
toNumericConverts value to and validates as number.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
value | number | string | Yes | - | Number representation; if null, returns 0. |
options | object | No | - | Custom options to apply. |
options.decimal | boolean | No | true | If true, retains decimal point. |
options.math | string | No | - | trunc, ceil, round, floor. |
(number): Returns formatted number.toNumeric('1.3');
// => 1.3
toNumeric(1.3);
// => 1.3
toNumeric('1.3', { decimal: false });
// => 1
toNumeric('1.3', { math: 'ceil' });
// => 2
toNumeric(1.3, { math: 'floor' });
// => 1
toNumeric(['1.3', 1], { math: 'floor' });
// => NaN
toNumeric({ 0: 1 });
// => NaN
toRGBaConverts color from Name or HEX code to RGBa value.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
color | string | Yes | - | Can be Name or HEX code (e.g. white, #DDD). |
alpha | number | No | 1 | Set custom alpha value. |
(string): Returns RGBa value.toRGBa('purple');
// => rgba(128,0,128,1)
toRGBa('#DDD', 0.5);
// => rgba(221,221,221,0.5)
trimWhitespaceRemoves leading and trailing spaces and replaces multiple white spaces, tabs and newlines with one space.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
text | string | Yes | - | Text to trim. |
(string): Returns trimmed text.trimWhitespace(' _the quiCK--brown FOx !');
// => _the quiCK--brown FOx !
Check Changelog for a detailed list of changes.
Head over to Discussions where you can ask questions, request new features or voice your ideas and suggestions.
This package is available under the BSD 3-Clause license. It also includes external libraries that are available under a variety of licenses. See LICENSE for the full license text.
FAQs
Utility library.
The npm package @rashedmakkouk/dev-utils receives a total of 12 weekly downloads. As such, @rashedmakkouk/dev-utils popularity was classified as not popular.
We found that @rashedmakkouk/dev-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
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.