How to use the color-string.to function in color-string

To help you get started, we’ve selected a few color-string examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tracespace / tracespace / packages / pcb-stackup-core / lib / _board-style.js View on Github external
var colorClass = function(layer) {
    var style = 'color: ' + colors[layer] + ';'

    // convert rgba to hex and opacity for inkscape compatibility
    if (/rgba/.test(colors[layer])) {
      var rgba = colorString.get.rgb(colors[layer])

      if (rgba) {
        var hex = colorString.to.hex(rgba).slice(0, 7)

        style = 'color: ' + hex + '; opacity: ' + rgba[3] + ';'
      }
    }

    return '.' + prefix + layer + ' {' + style + '}'
  }
github alexcambose / motus / src / helpers / dom.js View on Github external
export const getValue = value => {
  /// call getValue recursively for each item in the array
  if (isArray(value)) {
    return value.map(getValue);
  }
  value = String(value);
  // check if it is a color
  if (colorString.get(value)) {
    // returns a rgb array that needs to be further converted into rgb string
    const rgbArr = colorString.get.rgb(value);
    // convert array to rgb/rgba
    const color = colorString.to.rgb(rgbArr);
    return [color, COLOR_UNIT];
  }
  const unitReg = /([-0-9.]+)(cm|mm|in|px|pt|pc|em|ex|ch|%|rem|vw|vh|vmin|vmax|deg)*/;

  const match = value.match(unitReg);
  if (match && match.length === 3) {
    const value = parseFloat(match[1]);
    const unit = match[2] || NO_UNIT;
    return [value, unit];
  }
  throwError(NO_VALUE_SPECIFIED);
};
github diegomura / react-pdf / src / stylesheet / transformColors.js View on Github external
import colorString from 'color-string';
import hlsToHex from 'hsl-to-hex';

const isRgb = R.test(/rgb/g);
const isRgba = R.test(/rgba/g);
const isHsl = R.test(/hsl/g);
const isHsla = R.test(/hsla/g);

/**
 * Transform rgb color to hexa
 *
 * @param {String} styles value
 * @returns {Object} transformed value
 */
const parseRgb = R.compose(
  colorString.to.hex,
  colorString.get.rgb,
);

/**
 * Transform Hsl color to hexa
 *
 * @param {String} styles value
 * @returns {Object} transformed value
 */
const parseHsl = R.compose(
  R.toUpper,
  R.apply(hlsToHex),
  R.map(Math.round),
  colorString.get.hsl,
);
github tedconf / react-shed / es / index.js View on Github external
var getPropsForColor = function getPropsForColor(value, theme) {
  if (isValid('color')(value)) {
    if (value === 'transparent') {
      return 'transparent';
    }
    if (value === 'currentColor') {
      return 'currentColor';
    }
    if (value === 'inherit') {
      return 'inherit';
    }
    var alpha = /(.+)(\.\d)/.exec(value);
    if (alpha) {
      var transparentColor = color.get(theme.colors['' + alpha[1]]);
      transparentColor.value[3] = alpha[2];
      return color.to.rgb(transparentColor.value);
    }
    return theme.colors[value];
  }

  return value;
};
github tinkerhub / tinkerhub / lib / values / color.js View on Github external
conversions.add('rgb', 'hex', function(values) {
	return string.to.hex(values);
});
github ThePacielloGroup / CCAe / src / CCAcolor.js View on Github external
Color.prototype.string=function (places) {
    var self = (this.model in colorString.to || this.model == "hsv") ? this : this.rgb();
    self = self.round(typeof places === 'number' ? places : 1);
    var args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);

    if (this.model == "hsv") {
        var hsva = swizzle(args);
        return hsva.length < 4 || hsva[3] === 1
            ? 'hsv(' + hsva[0] + ', ' + hsva[1] + '%, ' + hsva[2] + '%)'
            : 'hsva(' + hsva[0] + ', ' + hsva[1] + '%, ' + hsva[2] + '%, ' + hsva[3] + ')';    
    } else {
        return colorString.to[self.model](args);    
    }
},
github ThePacielloGroup / CCAe / src / CCAcolor.js View on Github external
Color.prototype.string=function (places) {
    var self = (this.model in colorString.to || this.model == "hsv") ? this : this.rgb();
    self = self.round(typeof places === 'number' ? places : 1);
    var args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);

    if (this.model == "hsv") {
        var hsva = swizzle(args);
        return hsva.length < 4 || hsva[3] === 1
            ? 'hsv(' + hsva[0] + ', ' + hsva[1] + '%, ' + hsva[2] + '%)'
            : 'hsva(' + hsva[0] + ', ' + hsva[1] + '%, ' + hsva[2] + '%, ' + hsva[3] + ')';    
    } else {
        return colorString.to[self.model](args);    
    }
},
github codesandbox / codesandbox-client / standalone-packages / vscode-extensions / out / extensions / vscodevim.vim-1.2.0 / node_modules / color / index.js View on Github external
string: function (places) {
		var self = this.model in colorString.to ? this : this.rgb();
		self = self.round(typeof places === 'number' ? places : 1);
		var args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);
		return colorString.to[self.model](args);
	},
github Qix- / color / index.js View on Github external
hex: function (val) {
		if (arguments.length) {
			return new Color(val);
		}

		return colorString.to.hex(this.rgb().round().color);
	},
github jacobmischka / ics-merger / dist / utils.js View on Github external
export function rgbaOverRgb(rgba) {
	var rgb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [255, 255, 255];

	rgba = colorToArray(rgba);
	rgb = colorToArray(rgb);

	if (rgba.length < 4 || rgba[rgba.length - 1] === 1) return colorString.to.rgb(rgba);

	var rgbaAlpha = rgba.pop();

	var resultPieces = [];
	for (var i = 0; i < rgb.length; i++) {
		resultPieces.push(rgb[i] + (rgba[i] - rgb[i]) * rgbaAlpha);
	}

	return colorString.to.rgb(resultPieces);
}