How to use cssesc - 7 common examples

To help you get started, we’ve selected a few cssesc 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 postcss / postcss-selector-parser / src / selectors / attribute.js View on Github external
smartQuoteMark (options) {
        let v = this.value;
        let numSingleQuotes = v.replace(/[^']/g, '').length;
        let numDoubleQuotes = v.replace(/[^"]/g, '').length;
        if (numSingleQuotes + numDoubleQuotes === 0) {
            let escaped = cssesc(v, {isIdentifier: true});
            if (escaped === v) {
                return Attribute.NO_QUOTE;
            } else {
                let pref = this.preferredQuoteMark(options);
                if (pref === Attribute.NO_QUOTE) {
                    // pick a quote mark that isn't none and see if it's smaller
                    let quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
                    let opts = CSSESC_QUOTE_OPTIONS[quote];
                    let quoteValue = cssesc(v, opts);
                    if (quoteValue.length < escaped.length) {
                        return quote;
                    }
                }
                return pref;
            }
        } else if (numDoubleQuotes === numSingleQuotes) {
github postcss / postcss-selector-parser / src / selectors / attribute.js View on Github external
smartQuoteMark (options) {
        let v = this.value;
        let numSingleQuotes = v.replace(/[^']/g, '').length;
        let numDoubleQuotes = v.replace(/[^"]/g, '').length;
        if (numSingleQuotes + numDoubleQuotes === 0) {
            let escaped = cssesc(v, {isIdentifier: true});
            if (escaped === v) {
                return Attribute.NO_QUOTE;
            } else {
                let pref = this.preferredQuoteMark(options);
                if (pref === Attribute.NO_QUOTE) {
                    // pick a quote mark that isn't none and see if it's smaller
                    let quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
                    let opts = CSSESC_QUOTE_OPTIONS[quote];
                    let quoteValue = cssesc(v, opts);
                    if (quoteValue.length < escaped.length) {
                        return quote;
                    }
                }
                return pref;
            }
        } else if (numDoubleQuotes === numSingleQuotes) {
            return this.preferredQuoteMark(options);
        } else if ( numDoubleQuotes < numSingleQuotes) {
            return Attribute.DOUBLE_QUOTE;
        } else {
            return Attribute.SINGLE_QUOTE;
        }
    }
github postcss / postcss-selector-parser / src / selectors / attribute.js View on Github external
_syncRawValue () {
        let rawValue = cssesc(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
        if (rawValue === this._value) {
            if (this.raws) {
                delete this.raws.value;
            }
        } else {
            this.raws.value = rawValue;
        }
    }
github postcss / postcss-selector-parser / src / selectors / attribute.js View on Github external
_handleEscapes (prop, value) {
        if (this._constructed) {
            let escaped = cssesc(value, {isIdentifier: true});
            if (escaped !== value) {
                this.raws[prop] = escaped;
            } else {
                delete this.raws[prop];
            }
        }
    }
github last-hit-aab / last-hit / main / recorder / index.ts View on Github external
let result = nodeName;
		if (
			isTargetNode &&
			nodeName.toLowerCase() === 'input' &&
			elm.getAttribute('type') &&
			(!id || nodesMap.shouldIgnore(id)) &&
			!elm.getAttribute('class')
		) {
			result += '[type=' + cssesc(elm.getAttribute('type')) + ']';
		}
		if (needsNthChild) {
			result += ':nth-child(' + (ownIndex + 1) + ')';
		} else if (needsClassNames) {
			for (const prefixedName of prefixedOwnClassNamesArray) {
				result += '.' + cssesc(prefixedName.slice(1));
			}
		}

		return new StepPath(result, false);
	}
	private createCssPathFromNode(node: MyNode, nodesMap: NodesMap): string {
github kezoo / sprite-webpack-plugin / lib / templates / sprite.js View on Github external
template.items = cssItems.map( (item) => {
    item.image = item.image.replace(/\\/g, '\/');
    item.escaped_image = item.escaped_image.replace(/\\/g, '\/');
    item.name = formatWords([clsNamePrefix, item.name], options.connector);
    item['class'] = '.' + cssesc(item.name, {isIdentifier: true});
    if (wEnlarge) {
      const insertIndex = item.escaped_image.lastIndexOf('.');

      if (options.reqBase64) {
        spriteImgData.forEach( (item) => {
          if (item.imgName.toLowerCase() === tImgNameEnlarged.toLowerCase()) {
            enlargedImgData = item.base64;
          }
        })
      }

      if (!options.reqBase64 && insertIndex > 0) {
        enlargedImgData = `${item.escaped_image.slice(0, insertIndex)}@${wEnlarge}x${item.escaped_image.slice(insertIndex)}`;
      }

      item['enlargedImage'] = enlargedImgData;
github riot / compiler / src / generators / css / index.js View on Github external
const escapeIdentifier = identifier => escapeBackslashes(cssEscape(identifier, {
  isIdentifier: true
}))

cssesc

A JavaScript library for escaping CSS strings and identifiers while generating the shortest possible ASCII-only output.

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis

Popular cssesc functions