How to use the @create-figma-plugin/utilities/src/number.evaluateNumericExpression function in @create-figma-plugin/utilities

To help you get started, we’ve selected a few @create-figma-plugin/utilities 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 yuanqing / create-figma-plugin / packages / ui / src / components / textbox / textbox-numeric / textbox-numeric.js View on Github external
function (event) {
      const keyCode = event.keyCode
      if (keyCode === ESCAPE_KEY_CODE) {
        if (propagateEscapeKeyDown === false) {
          event.stopPropagation()
        }
        inputElementRef.current.blur()
        return
      }
      if (keyCode === DOWN_KEY_CODE || keyCode === UP_KEY_CODE) {
        event.preventDefault()
        const evaluatedValue = evaluateNumericExpression(value)
        if (
          (event.keyCode === DOWN_KEY_CODE && evaluatedValue <= minimum) ||
          (event.keyCode === UP_KEY_CODE && evaluatedValue >= maximum)
        ) {
          return
        }
        const delta = event.shiftKey === true ? bigIncrement : smallIncrement
        const newValue =
          event.keyCode === DOWN_KEY_CODE
            ? Math.max(evaluatedValue - delta, minimum)
            : Math.min(evaluatedValue + delta, maximum)
        const significantFiguresCount = countSignificantFigures(
          nonDigitRegex.test(value) === true ? `${evaluatedValue}` : value
        )
        inputElementRef.current.value = formatSignificantFigures(
          newValue,
github yuanqing / create-figma-plugin / packages / ui / src / components / textbox / textbox-numeric / textbox-numeric.js View on Github external
significantFiguresCount
        )
        handleInput()
        handleFocus()
        return
      }
      if (event.ctrlKey === true || event.metaKey === true) {
        return
      }
      if (isKeyCodeCharacterGenerating(event.keyCode) === true) {
        const nextValue = computeNextValue(inputElementRef.current, event.key)
        if (isValidNumericInput(nextValue, isInteger) === false) {
          event.preventDefault()
          return
        }
        const evaluatedValue = evaluateNumericExpression(nextValue)
        if (evaluatedValue < minimum || evaluatedValue > maximum) {
          event.preventDefault()
        }
      }
    },
    [

@create-figma-plugin/utilities

An extensive library of utility functions for common Figma/FigJam plugin/widget operations

MIT
Latest version published 13 days ago

Package Health Score

66 / 100
Full package analysis