Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqueleite42 authored Oct 20, 2021
1 parent 5e59890 commit b0dc07c
Show file tree
Hide file tree
Showing 83 changed files with 5,305 additions and 28 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@

// Spell Checker
"cSpell.words": [
"DMYS",
"injectables",
"Luma",
"MDYS",
"nodemodules",
"prebuild",
"sonarjs",
"techmmunity",
"tsbuildinfo",
"Typeof",
"vercel"
"vercel",
"YMDS"
]
}
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

## [1.2.0] - 2021-10-19

### Added

- `getHexColorLuma`
- `hasEmojis`
- `hasHtmlTags`
- `hasUrl`
- `isBrazilianPhone`
- `isCpf`
- `isDarkHexColor`
- `isDate`
- `isDateDMY`
- `isDateDMYS`
- `isDateMDY`
- `isDateMDYS`
- `isDateYMD`
- `isDateYMDS`
- `isDivisibleByTen`
- `isEmail`
- `isEmoji`
- `isEven`
- `isHerokuApiKey`
- `isHexColor`
- `isIpv4`
- `isIpv4WithMask`
- `isLeap`
- `isLightHexColor`
- `isMaskedCpf`
- `isNumeric`
- `isOdd`
- `isStrongPassword`
- `isUrl`
- `isUsername`
- `isUuidV4`

### Changed

### Removed

## [1.1.0] - 2021-10-17

### Added
Expand Down
65 changes: 59 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,67 @@ npm i @techmmunity/utils

# Docs

## Miscellaneous

| function | description |
| ---------- | ----------------------------------------------- |
| `cleanObj` | Remove undefined and null values from an object |

## `get*`

| function | description |
| ---------------------- | ---------------------------------------------------------------------- |
| `cleanObj` | Remove undefined and null values from an object |
| `getArrayUniqueValues` | Remove duplicated values of an array (only work with primitive values) |
| `getHexColorLuma` | Return the color luma of a hex color |
| `getEnumValues` | Return the enum values |
| `getTypeof` | Fix native "typeof" |
| `hasRequiredEnvVars` | Verify if all env vars are defined |
| `isEmptyArray` | Checks if is an array and it's empty |
| `isEmptyObject` | Checks if is an object and it's empty |
| `isNotEmptyArray` | Checks if is an array and it's NOT empty |
| `isNotEmptyObject` | Checks if is an object and it's NOT empty |

## `has*`

| function | description |
| -------------------- | ---------------------------------- |
| `hasEmojis` | Return true if value has emojis |
| `hasHtmlTags` | Return true if value has html tags |
| `hasRequiredEnvVars` | Verify if all env vars are defined |
| `hasUrl` | Return true if value has a url |

## `is*`

| function | description |
| ------------------ | ------------------------------------------------------------ |
| `isBrazilianPhone` | Return true if value is a brazilian phone |
| `isCpf` | Return true if value is a CPF |
| `isDarkHexColor` | Return true if value is a dark hex color |
| `isDate` | Return true if value is a valid date in the specified format |
| `isDateDMY` | Return true if value is a valid date DD-MM-YYY |
| `isDateDMYS` | Return true if value is a valid date DD/MM/YYY |
| `isDateMDY` | Return true if value is a valid date MM-DD-YYY |
| `isDateMDYS` | Return true if value is a valid date MM/DD/YYY |
| `isDateYMD` | Return true if value is a valid date YYYY-MM-DD |
| `isDateYMDS` | Return true if value is a valid date YYYY/MM/DD |
| `isDivisibleByTen` | Return true if value is divisible by ten |
| `isEmail` | Return true if value is a valid email |
| `isEmoji` | Return true if value is an emoji (has some false-positives!) |
| `isEmptyArray` | Checks if is an array and it's empty |
| `isEmptyObject` | Checks if is an object and it's empty |
| `isEven` | Return true if value is a even number |
| `isHerokuApiKey` | Return true if value is a heroku api key |
| `isHexColor` | Return true if value is a valid hex color |
| `isIpv4` | Return true if value is a valid ipv4 |
| `isIpv4WithMask` | Return true if value is a valid ipv4 with mask |
| `isLeap` | Return true if value is a leap year |
| `isLightHexColor` | Return true if value is a light hex color |
| `isMaskedCpf` | Return true if value is a masked CPF |
| `isNumeric` | Return true if value is a numeric string |
| `isOdd` | Return true if value is a odd number |
| `isStrongPassword` | Return true if value is a strong password |
| `isUrl` | Return true if value is a valid url |
| `isUsername` | Return true if value is a valid username |
| `isUuidV4` | Return true if value is a valid uuid (v4) |

## `isNot*`

| function | description |
| ------------------ | ----------------------------------------- |
| `isNotEmptyArray` | Checks if is an array and it's NOT empty |
| `isNotEmptyObject` | Checks if is an object and it's NOT empty |
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ module.exports = {
resetMocks: true,
coverageThreshold: {
global: {
statements: 96.29,
branches: 92.85,
statements: 98.64,
branches: 96.74,
functions: 100,
lines: 97.61,
lines: 99.55,
},
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@techmmunity/utils",
"version": "1.1.0",
"version": "1.2.0",
"main": "index.js",
"types": "index.d.ts",
"license": "Apache-2.0",
Expand Down
30 changes: 29 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export * from "./lib/clean-obj";
* ---------------------------------------------------------------------------
*/

export * from "./lib/get-typeof";
export * from "./lib/get-array-unique-values";
export * from "./lib/get-enum-values";
export * from "./lib/get-hex-color-luma";
export * from "./lib/get-typeof";

/**
* ---------------------------------------------------------------------------
Expand All @@ -28,7 +29,10 @@ export * from "./lib/get-enum-values";
* ---------------------------------------------------------------------------
*/

export * from "./lib/has-emojis";
export * from "./lib/has-html-tags";
export * from "./lib/has-required-env-vars";
export * from "./lib/has-url";

/**
* ---------------------------------------------------------------------------
Expand All @@ -38,8 +42,32 @@ export * from "./lib/has-required-env-vars";
* ---------------------------------------------------------------------------
*/

export * from "./lib/is-brazilian-phone";
export * from "./lib/is-cpf";
export * from "./lib/is-dark-hex-color";
export * from "./lib/is-date";
export * from "./lib/is-date-dmy";
export * from "./lib/is-date-dmys";
export * from "./lib/is-date-mdy";
export * from "./lib/is-date-mdys";
export * from "./lib/is-date-ymd";
export * from "./lib/is-date-ymds";
export * from "./lib/is-divisible-by-ten";
export * from "./lib/is-email";
export * from "./lib/is-emoji";
export * from "./lib/is-empty-array";
export * from "./lib/is-empty-object";
export * from "./lib/is-even";
export * from "./lib/is-heroku-api-key";
export * from "./lib/is-hex-color";
export * from "./lib/is-ipv4";
export * from "./lib/is-ipv4-with-mask";
export * from "./lib/is-numeric";
export * from "./lib/is-odd";
export * from "./lib/is-strong-password";
export * from "./lib/is-url";
export * from "./lib/is-username";
export * from "./lib/is-uuid-v4";

/**
* ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/lib/clean-obj/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTypeof } from "lib/get-typeof";
import { getTypeof } from "../get-typeof";

export const cleanObj = <T extends Record<string, any>>(obj: T) => {
if (getTypeof(obj) !== "object") {
Expand Down
40 changes: 40 additions & 0 deletions src/lib/get-hex-color-luma/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */

import { isHexColor } from "../is-hex-color";

const getColorWithCorrectLength = (color: string) => {
if (color.length === 3) {
const colorSplitted = color.split("");

const [r, g, b] = colorSplitted;

/**
* Duplicate the values, to make the code have length of six
*/
const colorWithLengthSix = [r, r, g, g, b, b];

return colorWithLengthSix.join("");
}

return color;
};

export const getHexColorLuma = (color: string) => {
if (!isHexColor(color)) return;

const colorWithOutHashtag = color.substring(1);

const colorWithLengthSix = getColorWithCorrectLength(colorWithOutHashtag);

const rgb = parseInt(colorWithLengthSix, 16);

const r = (rgb >> 16) & 0xff;
const g = (rgb >> 8) & 0xff;
const b = (rgb >> 0) & 0xff;

const rLuma = 0.2126 * r;
const gLuma = 0.7152 * g;
const bLuma = 0.0722 * b;

return rLuma + gLuma + bLuma;
};
Loading

0 comments on commit b0dc07c

Please sign in to comment.