How to use the color-string.get 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 gridsome / gridsome / gridsome / lib / app / loadConfig.js View on Github external
config.templatesDir = resolve(localConfig._templatesDir || './src/templates')
  config.templates = normalizeTemplates(context, config, localConfig)
  config.permalinks = normalizePermalinks(localConfig.permalinks)
  config.componentParsers = []

  config.chainWebpack = localConfig.chainWebpack
  config.configureWebpack = localConfig.configureWebpack
  config.configureServer = localConfig.configureServer

  config.images = {
    defaultBlur: 40,
    backgroundColor: null,
    ...localConfig.images
  }

  if (!colorString.get(config.images.backgroundColor || '')) {
    config.images.backgroundColor = null
  }

  config.runtimeCompiler = localConfig.runtimeCompiler || false

  config.transpileDependencies = Array.isArray(localConfig.transpileDependencies)
    ? localConfig.transpileDependencies.slice()
    : []

  // max cache age for html markup in serve mode
  config.maxCacheAge = localConfig.maxCacheAge || 1000

  config.siteUrl = localConfig.siteUrl || ''
  config.siteName = localConfig.siteName || path.parse(context).name
  config.titleTemplate = localConfig.titleTemplate || `%s - ${config.siteName}`
  config.siteDescription = localConfig.siteDescription || ''
github codesandbox / codesandbox-client / standalone-packages / vscode-extensions / out / extensions / vscodevim.vim-1.2.0 / node_modules / color / index.js View on Github external
throw new Error('Unknown model: ' + model);
	}

	var i;
	var channels;

	if (!obj) {
		this.model = 'rgb';
		this.color = [0, 0, 0];
		this.valpha = 1;
	} else if (obj instanceof Color) {
		this.model = obj.model;
		this.color = obj.color.slice();
		this.valpha = obj.valpha;
	} else if (typeof obj === 'string') {
		var result = colorString.get(obj);
		if (result === null) {
			throw new Error('Unable to parse color from string: ' + obj);
		}

		this.model = result.model;
		channels = convert[this.model].channels;
		this.color = result.value.slice(0, channels);
		this.valpha = typeof result.value[channels] === 'number' ? result.value[channels] : 1;
	} else if (obj.length) {
		this.model = model || 'rgb';
		channels = convert[this.model].channels;
		var newArr = _slice.call(obj, 0, channels);
		this.color = zeroArray(newArr, channels);
		this.valpha = typeof obj[channels] === 'number' ? obj[channels] : 1;
	} else if (typeof obj === 'number') {
		// this is always RGB - can be converted later on.
github gridsome / gridsome / gridsome / lib / app / queue / ImageProcessQueue.js View on Github external
let imageSizes = imageWidths.filter(size => size <= imageWidth)
    const maxWidth = Math.max(...imageSizes, 0)

    if (!options.imageWidths) {
      if (imageWidth > maxWidth || imageSizes.length === 0) {
        imageSizes.push(imageWidth)
      }

      imageSizes = reject(imageSizes, (width, i, arr) => {
        return arr[i + 1] - width < minSizeDistance
      })
    }

    // validate color string
    if (options.background && !colorString.get(options.background)) {
      options.background = this.config.imageBackgroundColor
    } else if (this.config.imageBackgroundColor) {
      options.background = this.config.imageBackgroundColor
    }

    const cacheKey = genHash(filePath + hash + JSON.stringify(options)).substr(0, 7)

    const createDestPath = (filename, imageOptions) => {
      if (process.env.GRIDSOME_MODE === 'serve') {
        const key = process.env.GRIDSOME_TEST ? 'test' : cacheKey
        const query = '?' + createOptionsQuery(imageOptions.concat({ key: 'key', value: key }))
        return path.join('/', imagesDir, forwardSlash(relPath)) + query
      }

      return path.join(imagesDir, filename)
    }
github jacobmischka / ics-merger / src / utils.js View on Github external
function colorToArray(color: Array | string | Object): Array {
	if (Array.isArray(color)) {
		return color;
	} else {
		switch(typeof color) {
			case 'object': return color.array();
			case 'string': return colorString.get(color).value;
		}
	}

	return [];
}
github danielguillan / sketch-syntax-highlighter / src / sketch-syntax-highlighter.js View on Github external
function hexToColor(hex) {
    const rgb = colorName[hex]
        ? colorName[hex]
        : colorString.get(hex).value;

    return NSColor.colorWithCalibratedRed_green_blue_alpha(
        rgb[0] / 255,
        rgb[1] / 255,
        rgb[2] / 255,
        1
    );
}
github tinkerhub / tinkerhub / lib / values / color.js View on Github external
function parse(color) {
	const t = TEMPERATURE.exec(color);
	if(t) {
		return new Color([ parseInt(t[1]) ], 'temperature');
	} else {
		const namedTemp = NAMED_TEMPERATURES[color.toLowerCase()];
		if(namedTemp) {
			return new Color([ namedTemp ], 'temperature');
		}

		const parsed = string.get(color);
		if(! parsed) {
			throw new Error('Unable to convert to color: ' + color);
		}
		return new Color(parsed.value, parsed.model);
	}
}
github littlstar / axis3d / src / core / color.js View on Github external
static parseString(string) {
    if ('string' == typeof string) {
      return ColorString.get(string.replace(/\s+/g, '')) || null
    }
    return null
  }
github tedconf / react-shed / src / index.js View on Github external
const getPropsForColor = (value, theme) => {
  if (isValid('color')(value)) {
    if (value === 'transparent') {
      return 'transparent';
    }
    if (value === 'currentColor') {
      return 'currentColor';
    }
    if (value === 'inherit') {
      return 'inherit';
    }
    const alpha = /(.+)(\.\d)/.exec(value);
    if (alpha) {
      const 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 / abstract-things / values / color.js View on Github external
function parse(color) {
	const t = TEMPERATURE.exec(color);
	if(t) {
		return new Color([ parseInt(t[1]) ], 'temperature');
	} else {
		const namedTemp = NAMED_TEMPERATURES[color.toLowerCase()];
		if(namedTemp) {
			return new Color([ namedTemp ], 'temperature');
		}

		const parsed = string.get(color);
		if(! parsed) {
			throw new Error('Unable to convert to color: ' + color);
		}
		return new Color(parsed.value, parsed.model);
	}
}