@rashedmakkouk/dev-utils
Advanced tools
+14
-1
| # Changelog | ||
| ## 0.22.0 (2021-06-11) | ||
| ### Documentation | ||
| - docs: Update methods `Example` content | ||
| ### Features | ||
| - feat: Bump package version from `0.14.5` to `0.14.6` | ||
| ## 0.22.0 (2021-06-08) | ||
@@ -18,6 +28,9 @@ | ||
| ### Documentation | ||
| - docs: Add method Parameters `Type` | ||
| ### Features | ||
| - feat: Bump package version from `0.14.0` to `0.14.1` | ||
| - docs: Add Parameters `Type` in `README.md` file | ||
@@ -24,0 +37,0 @@ ## 0.13.0 (2022-05-27) |
+1
-1
| { | ||
| "name": "@rashedmakkouk/dev-utils", | ||
| "version": "0.14.5", | ||
| "version": "0.14.6", | ||
| "description": "Utility library.", | ||
@@ -5,0 +5,0 @@ "displayName": "@rashedmakkouk/dev-utils", |
+190
-143
@@ -62,47 +62,45 @@ # Dev Utils | ||
| 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" | ||
| // } | ||
| // ] | ||
| // } | ||
| // Result. | ||
| { | ||
| 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" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
| ### `delay` | ||
| ### `delay` *(Promise)* | ||
| > Promise | ||
| Delays executions of a specified piece of code. | ||
@@ -124,3 +122,7 @@ | ||
| ```javascript | ||
| delay(1000, true); | ||
| try { | ||
| await delay(1000, true); | ||
| } catch (error) { | ||
| // Handle rejected Promise. | ||
| } | ||
| ``` | ||
@@ -152,3 +154,4 @@ | ||
| escape('abc', { stripQuote: true }); | ||
| // => abc | ||
| // Result. | ||
| abc | ||
| ``` | ||
@@ -176,3 +179,4 @@ | ||
| initials('John Unknown-Doe'); | ||
| // => JD | ||
| // Result. | ||
| 'JD' | ||
| ``` | ||
@@ -197,3 +201,3 @@ | ||
| - `(boolean)`: Returns true if supplied string passes checks, else false. | ||
| - `(boolean)`: Returns `true` if supplied string passes checks, else `false`. | ||
@@ -204,3 +208,4 @@ #### Example | ||
| isBase64('data:image/png;base64,<code>', { mimeRequired: true }); | ||
| // => true | ||
| // Result. | ||
| true | ||
| ``` | ||
@@ -223,3 +228,3 @@ | ||
| - `(boolean)`: Returns true if supplied payload passes checks, else false. | ||
| - `(boolean)`: Returns `true` if supplied payload passes checks, else `false`. | ||
@@ -230,21 +235,28 @@ #### Example | ||
| isValid('string', 'undefined'); | ||
| // => false | ||
| // Result. | ||
| false | ||
| isValid('string', '', { allowEmpty: true }); | ||
| // => true | ||
| // Result. | ||
| true | ||
| isValid('number', 'abc'); | ||
| // => false | ||
| // Result. | ||
| false | ||
| isValid('number', '123'); | ||
| // => false | ||
| // Result. | ||
| false | ||
| isValid('number', 0); | ||
| // => false | ||
| // Result. | ||
| false | ||
| isValid('object', ['abc']); | ||
| // => false | ||
| // Result. | ||
| false | ||
| isValid('object', {}, { allowEmpty: true }); | ||
| // => true | ||
| // Result. | ||
| true | ||
| ``` | ||
@@ -272,3 +284,4 @@ | ||
| joinPath(['/foo', 'bar', 'baz\\abc', './def', '..']); | ||
| // => '/foo/bar/baz/abc' | ||
| // Result. | ||
| '/foo/bar/baz/abc' | ||
| ``` | ||
@@ -297,10 +310,13 @@ | ||
| letterCase('_the quiCK--brown FOx_!', { letterCase: 'sentence' }); | ||
| // => '_The quick--brown fox_!' | ||
| // Result. | ||
| '_The quick--brown fox_!' | ||
| letterCase('the #quiCK brown FOx!', { letterCase: 'kebab' }); | ||
| // => 'the-quick-brown-fox' | ||
| // Result. | ||
| 'the-quick-brown-fox' | ||
| // Applies custom separators if supplied, else defaults to: [_-\s]+ | ||
| letterCase('_the quiCK--brown FOx_!', { letterCase: 'title' }); | ||
| // => 'The Quick Brown Fox!' | ||
| // Result. | ||
| 'The Quick Brown Fox!' | ||
| ``` | ||
@@ -334,6 +350,8 @@ | ||
| ms('1hr'); | ||
| // => 3600 | ||
| // Result. | ||
| 3600 | ||
| ms('1000'); | ||
| // => 1000 | ||
| // Result. | ||
| 1000 | ||
| ``` | ||
@@ -367,24 +385,24 @@ | ||
| 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] | ||
| // } | ||
| // Result. | ||
| { | ||
| 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 | ||
| // } | ||
| // Result. | ||
| { | ||
| entities: { | ||
| posts: { | ||
| 1: { id: 1, title: 'abc' } | ||
| }, | ||
| }, | ||
| result: 1 | ||
| } | ||
| ``` | ||
@@ -412,21 +430,21 @@ | ||
| 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" | ||
| // } | ||
| // Result. | ||
| { | ||
| 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" | ||
| } | ||
| ``` | ||
@@ -442,3 +460,3 @@ | ||
| - temp: File names stored in temporary or cache locations. | ||
| - uuid: v4 | ||
| - uuid: v4. | ||
@@ -464,15 +482,20 @@ #### Parameters | ||
| random('filename', { prefix: 'post' }); | ||
| // => post_2018-01-01_12-00-00_7f2a79ba-962e-4b35-96d0-28xf1d025107 | ||
| // Result. | ||
| 'post_2018-01-01_12-00-00_7f2a79ba-962e-4b35-96d0-28xf1d025107' | ||
| random('number', { min: 1000, max: 2000 }); | ||
| // => 1784 | ||
| // Result. | ||
| 1784 | ||
| random('title', { prefix: 'post' }); | ||
| // => post_2018-01-01_12-00-00 | ||
| random('title', { suffix: 'post' }); | ||
| // Result. | ||
| '2018-01-01_12-00-00_post' | ||
| random('temp'); | ||
| // => 2018-01-01_12-00-00_efc7438f-0a4d-4538-af87-b6984xe04688 | ||
| // Result. | ||
| '2018-01-01_12-00-00_efc7438f-0a4d-4538-af87-b6984xe04688' | ||
| random('uuid'); | ||
| // => 7e0ea78d-c170-4449-93fb-f5caxb952752 | ||
| // Result. | ||
| '7e0ea78d-c170-4449-93fb-f5caxb952752' | ||
| ``` | ||
@@ -500,3 +523,4 @@ | ||
| sanitize('<script>"the__ #quicK-- BROWN @foX_".js</script> <html><div>Html code</div></html>'); | ||
| // => "the__ #quicK-- BROWN @foX_".js Html code | ||
| // Result. | ||
| 'the__ #quicK-- BROWN @foX_.js Html code' | ||
| ``` | ||
@@ -522,9 +546,12 @@ | ||
| singular('posts'); | ||
| // => post | ||
| // Result. | ||
| 'post' | ||
| singular('commodities'); | ||
| // => commodity | ||
| // Result. | ||
| 'commodity' | ||
| singular({ key: 'posts' }); | ||
| // => '' | ||
| // Result. | ||
| '' | ||
| ``` | ||
@@ -551,14 +578,14 @@ | ||
| splitArray([{ id: 1, title: 'abc' }, { id: 2, title: 'def' }]); | ||
| // => | ||
| // [ | ||
| // { "id": 1, "title": "name1" }, | ||
| // { "id": 2, "title": "name2" } | ||
| // ] | ||
| // Result. | ||
| [ | ||
| { "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" }] | ||
| // ] | ||
| // Result. | ||
| [ | ||
| [{ "id": 1, "title": "name1" }], | ||
| [{ "id": 2, "title": "name2" }] | ||
| ] | ||
| ``` | ||
@@ -570,6 +597,6 @@ | ||
| - datetime: dddd, MMMM D at h:mA | ||
| - datetime: dddd, MMMM D at h:mA. | ||
| - fromNow: Relative time. | ||
| - short: ddd, MMM D | ||
| - sql: YYYY-MM-DD HH:mm:ss | ||
| - short: ddd, MMM D. | ||
| - sql: YYYY-MM-DD HH:mm:ss. | ||
@@ -592,15 +619,20 @@ #### Parameters | ||
| timestamp(Date.now()); | ||
| // => 31/12/2018 | ||
| // Result. | ||
| '31/12/2018' | ||
| timestamp(new Date('12/31/2018'), { format: 'datetime' }); | ||
| // => Monday, December 31 at 12:00AM | ||
| // Result. | ||
| 'Monday, December 31 at 12:00AM' | ||
| timestamp(Date(), { format: 'fromNow' }); | ||
| // => a few seconds ago | ||
| // Result. | ||
| 'a few seconds ago' | ||
| timestamp(moment('12/31/2018'), { format: 'short' }); | ||
| // => Mon, Dec 31 12:00AM | ||
| // Result. | ||
| 'Mon, Dec 31 12:00AM' | ||
| timestamp('12/31/2018 12:00', { format: 'sql' }); | ||
| // => 2018-12-31 12:00:00 | ||
| // Result. | ||
| '2018-12-31 12:00:00' | ||
| ``` | ||
@@ -629,15 +661,20 @@ | ||
| toArray('1', { toNumber: true }); | ||
| // => [1] | ||
| // Result. | ||
| [1] | ||
| toArray(['a', 'b', 'c']); | ||
| // => ['a', 'b', 'c'] | ||
| // Result. | ||
| ['a', 'b', 'c'] | ||
| toArray({ id: 1, title: 'name1' }); | ||
| // => [{ id: 1, title: 'name1' }] | ||
| // Result. | ||
| [{ id: 1, title: 'name1' }] | ||
| toArray('1,2,3'); | ||
| // => ['1', '2', '3'] | ||
| // Result. | ||
| ['1', '2', '3'] | ||
| toArray(' a-2-3 -', { toNumber: true, separator: '-' }); | ||
| // => [NaN, 2, 3] | ||
| // Result. | ||
| [NaN, 2, 3] | ||
| ``` | ||
@@ -666,21 +703,28 @@ | ||
| toNumeric('1.3'); | ||
| // => 1.3 | ||
| // Result. | ||
| 1.3 | ||
| toNumeric(1.3); | ||
| // => 1.3 | ||
| // Result. | ||
| 1.3 | ||
| toNumeric('1.3', { decimal: false }); | ||
| // => 1 | ||
| // Result. | ||
| 1 | ||
| toNumeric('1.3', { math: 'ceil' }); | ||
| // => 2 | ||
| // Result. | ||
| 2 | ||
| toNumeric(1.3, { math: 'floor' }); | ||
| // => 1 | ||
| // Result. | ||
| 1 | ||
| toNumeric(['1.3', 1], { math: 'floor' }); | ||
| // => NaN | ||
| // Result. | ||
| NaN | ||
| toNumeric({ 0: 1 }); | ||
| // => NaN | ||
| // Result. | ||
| NaN | ||
| ``` | ||
@@ -707,6 +751,8 @@ | ||
| toRGBa('purple'); | ||
| // => rgba(128,0,128,1) | ||
| // Result. | ||
| 'rgba(128,0,128,1)' | ||
| toRGBa('#DDD', 0.5); | ||
| // => rgba(221,221,221,0.5) | ||
| // Result. | ||
| 'rgba(221,221,221,0.5)' | ||
| ``` | ||
@@ -733,3 +779,4 @@ | ||
| trimWhitespace(' _the quiCK--brown FOx !'); | ||
| // => _the quiCK--brown FOx ! | ||
| // Result. | ||
| '_the quiCK--brown FOx !' | ||
| ``` | ||
@@ -736,0 +783,0 @@ |
245861
0.08%791
6.32%