LegacySyncFunction

LegacySyncFunction: ((this: LegacyPluginThis, args: LegacyValue[]) => LegacyValue)

Type declaration

    • (this: LegacyPluginThis, args: LegacyValue[]): LegacyValue
    • A synchronous callback that implements a custom Sass function. This can be passed to functions for either render or renderSync.

      If this throws an error, Sass will treat that as the function failing with that error message.

      const result = sass.renderSync({
      file: 'style.scss',
      functions: {
      "sum($arg1, $arg2)": (arg1, arg2) => {
      if (!(arg1 instanceof sass.types.Number)) {
      throw new Error("$arg1: Expected a number");
      } else if (!(arg2 instanceof sass.types.Number)) {
      throw new Error("$arg2: Expected a number");
      }
      return new sass.types.Number(arg1.getValue() + arg2.getValue());
      }
      }
      });

      Deprecated

      This only works with the legacy render and renderSync APIs. Use CustomFunction with compile, compileString, compileAsync, and compileStringAsync instead.

      Parameters

      Returns LegacyValue