How to use style-search - 2 common examples

To help you get started, we’ve selected a few style-search 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 stylelint / stylelint / src / rules / function-calc-no-unspaced-operator / index.js View on Github external
function checkSymbol(symbol) {
          const styleSearchOptions = {
            source: expression,
            target: symbol,
            functionArguments: "skip",
          }

          styleSearch(styleSearchOptions, match => {
            const index = match.startIndex

            // Deal with signs.
            // (@ and $ are considered "digits" here to allow for variable syntaxes
            // that permit signs in front of variables, e.g. `-$number`)
            // As is "." to deal with fractional numbers without a leading zero
            if ((symbol === "+" || symbol === "-") && /[\d@\$.]/.test(expression[index + 1])) {
              const expressionBeforeSign = expression.substr(0, index)

              // Ignore signs that directly follow a opening bracket
              if (expressionBeforeSign[expressionBeforeSign.length - 1] === "(") { return }

              // Ignore signs at the beginning of the expression
              if (/^\s*$/.test(expressionBeforeSign)) { return }

              // Otherwise, ensure that there is a real operator preceeding them
github stylelint / stylelint / src / rules / max-line-length / index.js View on Github external
optional: true,
    })
    if (!validOptions) { return }

    // Collapse all urls into something nice and short,
    // so they do not throw the game
    const rootString = root.toString().replace(/url\(.*\)/ig, "url()")

    const ignoreNonComments = optionsMatches(options, "ignore", "non-comments")
    const ignoreComments = optionsMatches(options, "ignore", "comments")

    // Check first line
    checkNewline({ endIndex: 0 })

    // Check subsequent lines
    styleSearch({ source: rootString, target: ["\n"], comments: "check" }, checkNewline)

    function complain(index) {
      report({
        index,
        result,
        ruleName,
        message: messages.expected(maxLength),
        node: root,
      })
    }

    function checkNewline(match) {
      const endOfLineIndicator = (rootString.indexOf("\r\n", match.endIndex) !== -1) ? "\r\n" : "\n"
      let nextNewlineIndex = rootString.indexOf(endOfLineIndicator, match.endIndex)

      // Accommodate last line

style-search

Search CSS(-like) strings

ISC
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis

Popular style-search functions