Skip to content

Latest commit

 

History

History
68 lines (51 loc) · 1.58 KB

File metadata and controls

68 lines (51 loc) · 1.58 KB

Utils

There are a couple of utilities included with lesshint which can be used when creating custom linters.

const utils = require('lesshint').utils;

isAbsoluteURL(str)

Check if a string is a absolute URL.

utils.isAbsoluteURL('http://example.com'); // true
utils.isAbsoluteURL('file.less'); // false

isVariable(str)

Check if a value is a Less variable.

utils.isVariable('@foo'); // true
utils.isVariable('blue'); // false

hasQuotes(str, style)

Check if a string is enclosed in quotes.

style values Description
any Check for any kind of quotes (default).
double Check for double quotes.
single Check for single quotes.
utils.hasQuotes'"foo"', 'any'); // true
utils.hasQuotes('foo', 'any'); // false

utils.hasQuotes('"foo"', 'double'); // true
utils.hasQuotes("'foo'", 'double'); // false

utils.hasQuotes("'foo'", 'single'); // true
utils.hasQuotes('"foo"', 'single'); // false

parseSelector(selector)

Parse a selector using postcss-selector-parser. Accepts a selector string or a PostCSS Rule node.

utils.parseSelector('.foo'); // Parser tree
utils.parseSelector(ruleNode); // Parser tree

parseValue(value, options)

Parse a value using postcss-values-parser.

options is any valid postcss-values-parser options. The default values are:

{
    loose: true
}
utils.parseValue('10px', {
    loose: false
}); // Parser tree