Spec-Zone.ru › Sass

CustomFunction<sync>

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

Type Parameters

  • sync extends "sync" | "async"

    A CustomFunction<'sync'> must return synchronously, but in return it can be passed to compile and compileString in addition to compileAsync and compileStringAsync.

    A CustomFunction<'async'> may either return synchronously or asynchronously, but it can only be used with compileAsync and compileStringAsync.

Type declaration

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

      constresult = sass.compile('style.scss', {
      functions: {
      "sum($arg1, $arg2)": (args) => {
      constarg1 = args[0].assertNumber('arg1');
      constvalue1 = arg1.value;
      constvalue2 = args[1].assertNumber('arg2')
      .convertValueToMatch(arg1, 'arg2', 'arg1');
      returnnewsass.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

      • args: Value[]

        An array of arguments passed by the function's caller. If the function takes arbitrary arguments, the last element will be a SassArgumentList.

      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.

  • Defined in js-api-doc/options.d.ts:77
sass
  • Compile
    • AsyncCompiler
    • Compiler
    • CompileResult
    • compile
    • compileAsync
    • compileString
    • compileStringAsync
    • initAsyncCompiler
    • initCompiler
  • Options
    • Options
    • StringOptions
    • OutputStyle
    • StringOptionsWithImporter
    • StringOptionsWithoutImporter
    • Syntax
  • Logger
    • Logger
      • silent
    • Logger
    • SourceLocation
    • SourceSpan
    • LoggerWarnOptions
  • Importer
    • NodePackageImporter
    • FileImporter
    • Importer
    • ImporterResult
  • Custom Function
    • CalculationInterpolation
    • CalculationOperation
    • SassArgumentList
    • SassBoolean
    • SassCalculation
    • SassColor
    • SassFunction
    • SassList
    • SassMap
    • SassMixin
    • SassNumber
    • SassString
    • Value
    • CalculationOperator
    • CalculationValue
    • CustomFunction
    • ListSeparator
    • sassFalse
    • sassNull
    • sassTrue
  • Other
    • Exception
    • CanonicalizeContext
    • Deprecations
    • LegacyFileOptions
    • ChannelName
    • ChannelNameHsl
    • ChannelNameHwb
    • ChannelNameLab
    • ChannelNameLch
    • ChannelNameRgb
    • ChannelNameXyz
    • ColorSpaceHsl
    • ColorSpaceHwb
    • ColorSpaceLab
    • ColorSpaceLch
    • ColorSpaceRgb
    • ColorSpaceXyz
    • GamutMapMethod
    • HueInterpolationMethod
    • KnownColorSpace
    • PolarColorSpace
    • PromiseOr
    • RectangularColorSpace
    • info
  • Legacy
    • types
      • Boolean
      • Color
      • Error
      • List
      • Map
      • Null
      • Number
      • String
    • LegacyException
    • LegacyImporterThis
    • LegacyPluginThis
    • LegacyResult
    • LegacySharedOptions
    • LegacyStringOptions
    • LegacyAsyncFunction
    • LegacyAsyncFunctionDone
    • LegacyAsyncImporter
    • LegacyFunction
    • LegacyImporter
    • LegacyImporterResult
    • LegacyOptions
    • LegacySyncFunction
    • LegacySyncImporter
    • LegacyValue
    • FALSE
    • NULL
    • TRUE
    • render
    • renderSync
  • Messages
    • Version
    • Deprecation
    • DeprecationOrId
    • DeprecationStatus
    • deprecations

© 2006–2025 the Sass team, and numerous contributors
Licensed under the MIT License.
https://sass-lang.com/documentation/js-api/types/CustomFunction

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API