CustomFunction<sync>

CustomFunction<sync extends "sync" | "async">: ((args: Value[]) => PromiseOr<Value, sync>)

Type Parameters

Type declaration

    • (args: Value[]): PromiseOr<Value, sync>
    • A callback that implements a custom Sass function. This can be passed to functions.

      const result = sass.compile('style.scss', {
      functions: {
      "sum($arg1, $arg2)": (args) => {
      const arg1 = args[0].assertNumber('arg1');
      const value1 = arg1.value;
      const value2 = args[1].assertNumber('arg2')
      .convertValueToMatch(arg1, 'arg2', 'arg1');
      return new sass.SassNumber(value1 + value2).coerceToMatch(arg1);
      }
      }
      });

      Throws

      any - This function may throw an error, which the Sass compiler will treat as the function call failing. If the exception object has a message property, it will be used as the wrapped exception's message; otherwise, the exception object's toString() will be used. This means it's safe for custom functions to throw plain strings.

      Parameters

      Returns PromiseOr<Value, sync>

      The function's result. This may be in the form of a Promise, but if it is the function may only be passed to compileAsync and compileStringAsync, not compile or compileString.