Skip to content

Instantly share code, notes, and snippets.

View negarjf's full-sized avatar
🤓

Negar negarjf

🤓
View GitHub Profile
@negarjf
negarjf / string-id-generator.js
Last active July 21, 2020 20:54
Generating unique random strings with optional prefix and postfix.
/**
* Generates random string id
*
* @param prefix
* @param postfix
* @returns {string}
*/
function generateId(prefix, postfix) {
prefix = prefix || "";
postfix = postfix || "";
@negarjf
negarjf / text-color-detector.js
Created September 14, 2018 13:27
Auto Text Color Detector
// Converts color code to RGB
//====================================
function colorCodeToRGB(colorCode){
var c;
var rgbaValidation = (/([R][G][B][A]?[(]\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(\s*,\s*((0\.[0-9]{1})|(1\.0)|(1)))?[)])/i.test(colorCode)) ;
var hexValidation = (/^#([A-Fa-f0-9]{3}){1,2}$/.test(colorCode));
if(hexValidation){
c= colorCode.substring(1).split('');