Skip to content

Commit b0dc07c

Browse files
1 parent 5e59890 commit b0dc07c

File tree

83 files changed

+5305
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+5305
-28
lines changed

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,17 @@
107107

108108
// Spell Checker
109109
"cSpell.words": [
110+
"DMYS",
110111
"injectables",
112+
"Luma",
113+
"MDYS",
111114
"nodemodules",
112115
"prebuild",
113116
"sonarjs",
114117
"techmmunity",
115118
"tsbuildinfo",
116119
"Typeof",
117-
"vercel"
120+
"vercel",
121+
"YMDS"
118122
]
119123
}

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Removed
1515

16+
## [1.2.0] - 2021-10-19
17+
18+
### Added
19+
20+
- `getHexColorLuma`
21+
- `hasEmojis`
22+
- `hasHtmlTags`
23+
- `hasUrl`
24+
- `isBrazilianPhone`
25+
- `isCpf`
26+
- `isDarkHexColor`
27+
- `isDate`
28+
- `isDateDMY`
29+
- `isDateDMYS`
30+
- `isDateMDY`
31+
- `isDateMDYS`
32+
- `isDateYMD`
33+
- `isDateYMDS`
34+
- `isDivisibleByTen`
35+
- `isEmail`
36+
- `isEmoji`
37+
- `isEven`
38+
- `isHerokuApiKey`
39+
- `isHexColor`
40+
- `isIpv4`
41+
- `isIpv4WithMask`
42+
- `isLeap`
43+
- `isLightHexColor`
44+
- `isMaskedCpf`
45+
- `isNumeric`
46+
- `isOdd`
47+
- `isStrongPassword`
48+
- `isUrl`
49+
- `isUsername`
50+
- `isUuidV4`
51+
52+
### Changed
53+
54+
### Removed
55+
1656
## [1.1.0] - 2021-10-17
1757

1858
### Added

README.md

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,67 @@ npm i @techmmunity/utils
4646

4747
# Docs
4848

49+
## Miscellaneous
50+
51+
| function | description |
52+
| ---------- | ----------------------------------------------- |
53+
| `cleanObj` | Remove undefined and null values from an object |
54+
55+
## `get*`
56+
4957
| function | description |
5058
| ---------------------- | ---------------------------------------------------------------------- |
51-
| `cleanObj` | Remove undefined and null values from an object |
5259
| `getArrayUniqueValues` | Remove duplicated values of an array (only work with primitive values) |
60+
| `getHexColorLuma` | Return the color luma of a hex color |
5361
| `getEnumValues` | Return the enum values |
5462
| `getTypeof` | Fix native "typeof" |
55-
| `hasRequiredEnvVars` | Verify if all env vars are defined |
56-
| `isEmptyArray` | Checks if is an array and it's empty |
57-
| `isEmptyObject` | Checks if is an object and it's empty |
58-
| `isNotEmptyArray` | Checks if is an array and it's NOT empty |
59-
| `isNotEmptyObject` | Checks if is an object and it's NOT empty |
63+
64+
## `has*`
65+
66+
| function | description |
67+
| -------------------- | ---------------------------------- |
68+
| `hasEmojis` | Return true if value has emojis |
69+
| `hasHtmlTags` | Return true if value has html tags |
70+
| `hasRequiredEnvVars` | Verify if all env vars are defined |
71+
| `hasUrl` | Return true if value has a url |
72+
73+
## `is*`
74+
75+
| function | description |
76+
| ------------------ | ------------------------------------------------------------ |
77+
| `isBrazilianPhone` | Return true if value is a brazilian phone |
78+
| `isCpf` | Return true if value is a CPF |
79+
| `isDarkHexColor` | Return true if value is a dark hex color |
80+
| `isDate` | Return true if value is a valid date in the specified format |
81+
| `isDateDMY` | Return true if value is a valid date DD-MM-YYY |
82+
| `isDateDMYS` | Return true if value is a valid date DD/MM/YYY |
83+
| `isDateMDY` | Return true if value is a valid date MM-DD-YYY |
84+
| `isDateMDYS` | Return true if value is a valid date MM/DD/YYY |
85+
| `isDateYMD` | Return true if value is a valid date YYYY-MM-DD |
86+
| `isDateYMDS` | Return true if value is a valid date YYYY/MM/DD |
87+
| `isDivisibleByTen` | Return true if value is divisible by ten |
88+
| `isEmail` | Return true if value is a valid email |
89+
| `isEmoji` | Return true if value is an emoji (has some false-positives!) |
90+
| `isEmptyArray` | Checks if is an array and it's empty |
91+
| `isEmptyObject` | Checks if is an object and it's empty |
92+
| `isEven` | Return true if value is a even number |
93+
| `isHerokuApiKey` | Return true if value is a heroku api key |
94+
| `isHexColor` | Return true if value is a valid hex color |
95+
| `isIpv4` | Return true if value is a valid ipv4 |
96+
| `isIpv4WithMask` | Return true if value is a valid ipv4 with mask |
97+
| `isLeap` | Return true if value is a leap year |
98+
| `isLightHexColor` | Return true if value is a light hex color |
99+
| `isMaskedCpf` | Return true if value is a masked CPF |
100+
| `isNumeric` | Return true if value is a numeric string |
101+
| `isOdd` | Return true if value is a odd number |
102+
| `isStrongPassword` | Return true if value is a strong password |
103+
| `isUrl` | Return true if value is a valid url |
104+
| `isUsername` | Return true if value is a valid username |
105+
| `isUuidV4` | Return true if value is a valid uuid (v4) |
106+
107+
## `isNot*`
108+
109+
| function | description |
110+
| ------------------ | ----------------------------------------- |
111+
| `isNotEmptyArray` | Checks if is an array and it's NOT empty |
112+
| `isNotEmptyObject` | Checks if is an object and it's NOT empty |

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ module.exports = {
1515
resetMocks: true,
1616
coverageThreshold: {
1717
global: {
18-
statements: 96.29,
19-
branches: 92.85,
18+
statements: 98.64,
19+
branches: 96.74,
2020
functions: 100,
21-
lines: 97.61,
21+
lines: 99.55,
2222
},
2323
},
2424
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@techmmunity/utils",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"main": "index.js",
55
"types": "index.d.ts",
66
"license": "Apache-2.0",

src/index.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ export * from "./lib/clean-obj";
1616
* ---------------------------------------------------------------------------
1717
*/
1818

19-
export * from "./lib/get-typeof";
2019
export * from "./lib/get-array-unique-values";
2120
export * from "./lib/get-enum-values";
21+
export * from "./lib/get-hex-color-luma";
22+
export * from "./lib/get-typeof";
2223

2324
/**
2425
* ---------------------------------------------------------------------------
@@ -28,7 +29,10 @@ export * from "./lib/get-enum-values";
2829
* ---------------------------------------------------------------------------
2930
*/
3031

32+
export * from "./lib/has-emojis";
33+
export * from "./lib/has-html-tags";
3134
export * from "./lib/has-required-env-vars";
35+
export * from "./lib/has-url";
3236

3337
/**
3438
* ---------------------------------------------------------------------------
@@ -38,8 +42,32 @@ export * from "./lib/has-required-env-vars";
3842
* ---------------------------------------------------------------------------
3943
*/
4044

45+
export * from "./lib/is-brazilian-phone";
46+
export * from "./lib/is-cpf";
47+
export * from "./lib/is-dark-hex-color";
48+
export * from "./lib/is-date";
49+
export * from "./lib/is-date-dmy";
50+
export * from "./lib/is-date-dmys";
51+
export * from "./lib/is-date-mdy";
52+
export * from "./lib/is-date-mdys";
53+
export * from "./lib/is-date-ymd";
54+
export * from "./lib/is-date-ymds";
55+
export * from "./lib/is-divisible-by-ten";
56+
export * from "./lib/is-email";
57+
export * from "./lib/is-emoji";
4158
export * from "./lib/is-empty-array";
4259
export * from "./lib/is-empty-object";
60+
export * from "./lib/is-even";
61+
export * from "./lib/is-heroku-api-key";
62+
export * from "./lib/is-hex-color";
63+
export * from "./lib/is-ipv4";
64+
export * from "./lib/is-ipv4-with-mask";
65+
export * from "./lib/is-numeric";
66+
export * from "./lib/is-odd";
67+
export * from "./lib/is-strong-password";
68+
export * from "./lib/is-url";
69+
export * from "./lib/is-username";
70+
export * from "./lib/is-uuid-v4";
4371

4472
/**
4573
* ---------------------------------------------------------------------------

src/lib/clean-obj/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getTypeof } from "lib/get-typeof";
1+
import { getTypeof } from "../get-typeof";
22

33
export const cleanObj = <T extends Record<string, any>>(obj: T) => {
44
if (getTypeof(obj) !== "object") {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint-disable @typescript-eslint/no-magic-numbers */
2+
3+
import { isHexColor } from "../is-hex-color";
4+
5+
const getColorWithCorrectLength = (color: string) => {
6+
if (color.length === 3) {
7+
const colorSplitted = color.split("");
8+
9+
const [r, g, b] = colorSplitted;
10+
11+
/**
12+
* Duplicate the values, to make the code have length of six
13+
*/
14+
const colorWithLengthSix = [r, r, g, g, b, b];
15+
16+
return colorWithLengthSix.join("");
17+
}
18+
19+
return color;
20+
};
21+
22+
export const getHexColorLuma = (color: string) => {
23+
if (!isHexColor(color)) return;
24+
25+
const colorWithOutHashtag = color.substring(1);
26+
27+
const colorWithLengthSix = getColorWithCorrectLength(colorWithOutHashtag);
28+
29+
const rgb = parseInt(colorWithLengthSix, 16);
30+
31+
const r = (rgb >> 16) & 0xff;
32+
const g = (rgb >> 8) & 0xff;
33+
const b = (rgb >> 0) & 0xff;
34+
35+
const rLuma = 0.2126 * r;
36+
const gLuma = 0.7152 * g;
37+
const bLuma = 0.0722 * b;
38+
39+
return rLuma + gLuma + bLuma;
40+
};

0 commit comments

Comments
 (0)