@deckdeckgo/utils
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,9 @@ | ||
<a name="1.2.0"></a> | ||
# 1.2.0 (2020-07-31) | ||
### Features | ||
- add functions `hexToRgb` and `rgbToHex` | ||
<a name="1.1.0"></a> | ||
@@ -2,0 +10,0 @@ |
@@ -135,3 +135,31 @@ 'use strict'; | ||
async function hexToRgb(hex) { | ||
if (!hex || hex === undefined || hex === '') { | ||
return undefined; | ||
} | ||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | ||
return result ? `${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)}` : undefined; | ||
} | ||
async function rgbToHex(rgb) { | ||
if (!rgb) { | ||
return undefined; | ||
} | ||
const toHex = (rgb) => { | ||
if (!rgb) { | ||
return undefined; | ||
} | ||
return `#${rgb.map((v) => v.toString(16).padStart(2, '0')).join('')}`; | ||
}; | ||
const extractRgb = (rgb) => { | ||
const match = rgb.match(/(\d+),\s*(\d+),\s*(\d+)/); | ||
if (!match) { | ||
return undefined; | ||
} | ||
return match.splice(1, 3).map((v) => Number(v)); | ||
}; | ||
return toHex(extractRgb(rgb)); | ||
} | ||
exports.debounce = debounce; | ||
exports.hexToRgb = hexToRgb; | ||
exports.injectCSS = injectCSS; | ||
@@ -147,2 +175,3 @@ exports.injectJS = injectJS; | ||
exports.lazyLoadSelectedLazyImagesComponent = lazyLoadSelectedLazyImagesComponent; | ||
exports.rgbToHex = rgbToHex; | ||
exports.unifyEvent = unifyEvent; |
export * from './utils/utils'; | ||
export * from './utils/image-utils'; | ||
export * from './utils/inject-utils'; | ||
export * from './utils/color-utils'; |
export * from './utils/utils'; | ||
export * from './utils/image-utils'; | ||
export * from './utils/inject-utils'; | ||
export * from './utils/color-utils'; |
{ | ||
"name": "@deckdeckgo/utils", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": "David Dal Busco", | ||
@@ -13,12 +13,12 @@ "description": "A collection of utils methods and functions developed for DeckDeckGo", | ||
"devDependencies": { | ||
"@types/node": "^13.9.1", | ||
"husky": "^4.2.3", | ||
"prettier": "1.19.1", | ||
"@types/node": "^14.0.27", | ||
"husky": "^4.2.5", | ||
"prettier": "2.0.5", | ||
"pretty-quick": "^2.0.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.1.0", | ||
"rollup": "^2.23.0", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-typescript": "^1.0.1", | ||
"tslib": "^1.11.1", | ||
"typescript": "^3.8.3" | ||
"tslib": "^2.0.0", | ||
"typescript": "^3.9.7" | ||
}, | ||
@@ -25,0 +25,0 @@ "main": "lib/index.cjs.js", |
19725
15
358