LegacyAsyncFunction

LegacyAsyncFunction: ((this: LegacyPluginThis, done: ((result: LegacyValue) => void)) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, arg5: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, arg1: LegacyValue, arg2: LegacyValue, arg3: LegacyValue, arg4: LegacyValue, arg5: LegacyValue, arg6: LegacyValue, done: LegacyAsyncFunctionDone) => void) | ((this: LegacyPluginThis, args: [LegacyValue[], LegacyAsyncFunctionDone]) => void)

An asynchronous callback that implements a custom Sass function. This can be passed to functions, but only for render.

An asynchronous function must return undefined. Its final argument will always be a callback, which it should call with the result of the function once it's done running.

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

sass.render({
file: 'style.scss',
functions: {
"sum($arg1, $arg2)": (arg1, arg2, done) => {
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");
}
done(new sass.types.Number(arg1.getValue() + arg2.getValue()));
}
}
}, (result, error) => {
// ...
});

This is passed one argument for each argument that's declared in the signature that's passed to functions. If the signature takes arbitrary arguments, they're passed as a single argument list in the last argument before the callback.

Deprecated

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