Spec-Zone.ru › Sass

SassNumber

Sass's number type.

Hierarchy

  • Value
    • SassNumber
  • Defined in js-api-doc/value/number.d.ts:10
Index

Constructors

constructor

Accessors

asInt asList denominatorUnits hasBrackets hasUnits isInt isTruthy numeratorUnits realNull separator value

Methods

assertBoolean assertCalculation assertColor assertFunction assertInRange assertInt assertMap assertMixin assertNoUnits assertNumber assertString assertUnit coerce coerceToMatch coerceValue coerceValueToMatch compatibleWithUnit convert convertToMatch convertValue convertValueToMatch equals get hasUnit hashCode sassIndexToListIndex tryMap

Constructors

constructor

  • new SassNumber(value: number, unit?: string | {
    denominatorUnits?: string[] | List<string>;
    numeratorUnits?: string[] | List<string>;
    }): SassNumber
  • Creates a new number with more complex units than just a single numerator.

    Upon construction, any compatible numerator and denominator units are simplified away according to the conversion factor between them.

    Parameters

    • value: number

      The number's numeric value.

    • Optional unit: string | {
      denominatorUnits?: string[] | List<string>;
      numeratorUnits?: string[] | List<string>;
      }

      If this is a string, it's used as the single numerator unit for the number.

    Returns SassNumber

    Overrides Value.constructor

    • Defined in js-api-doc/value/number.d.ts:32

Accessors

asInt

  • get asInt(): null | number
  • If value is an integer according to isInt, returns value rounded to that integer. If it's not an integer, returns null.

    Returns null | number

    • Defined in js-api-doc/value/number.d.ts:52

asList

  • get asList(): List<Value>
  • This value as a list.

    All SassScript values can be used as lists. Maps count as lists of pairs, and all other values count as single-value lists.

    Returns List<Value>

    An immutable List from the immutable package.

    Inherited from Value.asList

    • Defined in js-api-doc/value/index.d.ts:77

denominatorUnits

  • get denominatorUnits(): List<string>
  • This number's denominator units as an immutable List from the immutable package.

    Returns List<string>

    • Defined in js-api-doc/value/number.d.ts:64

hasBrackets

  • get hasBrackets(): boolean
  • Whether this value as a list has brackets.

    All SassScript values can be used as lists. Maps count as lists of pairs, and all other values count as single-value lists.

    Returns boolean

    Inherited from Value.hasBrackets

    • Defined in js-api-doc/value/index.d.ts:85

hasUnits

  • get hasUnits(): boolean
  • Whether this number has any numerator or denominator units.

    Returns boolean

    • Defined in js-api-doc/value/number.d.ts:67

isInt

  • get isInt(): boolean
  • Whether value is an integer according to Sass's equality logic.

    Returns boolean

    • Defined in js-api-doc/value/number.d.ts:46

isTruthy

  • get isTruthy(): boolean
  • Whether the value counts as true in an @if statement and other contexts.

    Returns boolean

    Inherited from Value.isTruthy

    • Defined in js-api-doc/value/index.d.ts:91

numeratorUnits

  • get numeratorUnits(): List<string>
  • This number's numerator units as an immutable List from the immutable package.

    Returns List<string>

    • Defined in js-api-doc/value/number.d.ts:58

realNull

  • get realNull(): null | Value
  • Returns JavaScript's null value if this is sassNull, and returns this otherwise.

    Returns null | Value

    Inherited from Value.realNull

    • Defined in js-api-doc/value/index.d.ts:97

separator

  • get separator(): ListSeparator
  • The separator for this value as a list.

    All SassScript values can be used as lists. Maps count as lists of pairs, and all other values count as single-value lists.

    Returns ListSeparator

    Inherited from Value.separator

    • Defined in js-api-doc/value/index.d.ts:105

value

  • get value(): number
  • This number's numeric value.

    Returns number

    • Defined in js-api-doc/value/number.d.ts:43

Methods

assertBoolean

  • assertBoolean(name?: string): SassBoolean
  • Throws if this isn't a SassBoolean.

    Functions should generally use isTruthy rather than requiring a literal boolean.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassBoolean

    Inherited from Value.assertBoolean

    • Defined in js-api-doc/value/index.d.ts:147

assertCalculation

  • assertCalculation(name?: string): SassCalculation
  • Throws if this isn't a SassCalculation.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassCalculation

    Inherited from Value.assertCalculation

    • Defined in js-api-doc/value/index.d.ts:155

assertColor

  • assertColor(name?: string): SassColor
  • Throws if this isn't a SassColor.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassColor

    Inherited from Value.assertColor

    • Defined in js-api-doc/value/index.d.ts:163

assertFunction

  • assertFunction(name?: string): SassFunction
  • Throws if this isn't a SassFunction.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassFunction

    Inherited from Value.assertFunction

    • Defined in js-api-doc/value/index.d.ts:171

assertInRange

  • assertInRange(min: number, max: number, name?: string): number
  • Returns value if it's within min and max. If value is equal to min or max according to Sass's equality, returns min or max respectively. Otherwise, throws an error.

    Parameters

    • min: number
    • max: number
    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns number

    • Defined in js-api-doc/value/number.d.ts:86

assertInt

  • assertInt(name?: string): number
  • If value is an integer according to isInt, returns it rounded to that integer. Otherwise, throws an error.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns number

    • Defined in js-api-doc/value/number.d.ts:76

assertMap

  • assertMap(name?: string): SassMap
  • Throws if this isn't a SassMap.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassMap

    Inherited from Value.assertMap

    • Defined in js-api-doc/value/index.d.ts:179

assertMixin

  • assertMixin(name?: string): SassMixin
  • Throws if this isn't a SassMixin.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassMixin

    Inherited from Value.assertMixin

    • Defined in js-api-doc/value/index.d.ts:187

assertNoUnits

  • assertNoUnits(name?: string): SassNumber
  • If this number has no units, returns it. Otherwise, throws an error.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassNumber

    • Defined in js-api-doc/value/number.d.ts:94

assertNumber

  • assertNumber(name?: string): SassNumber
  • Throws if this isn't a SassNumber.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassNumber

    Inherited from Value.assertNumber

    • Defined in js-api-doc/value/index.d.ts:195

assertString

  • assertString(name?: string): SassString
  • Throws if this isn't a SassString.

    Parameters

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassString

    Inherited from Value.assertString

    • Defined in js-api-doc/value/index.d.ts:203

assertUnit

  • assertUnit(unit: string, name?: string): SassNumber
  • If this number has unit as its only unit (and as a numerator), returns this number. Otherwise, throws an error.

    Parameters

    • unit: string
    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassNumber

    • Defined in js-api-doc/value/number.d.ts:103

coerce

  • coerce(newNumerators: string[] | List<string>, newDenominators: string[] | List<string>, name?: string): SassNumber
  • Returns a copy of this number, converted to the units represented by newNumerators and newDenominators.

    Unlike convert this does not throw an error if this number is unitless and either newNumerators or newDenominators are not empty, or vice-versa. Instead, it treats all unitless numbers as convertible to and from all units without changing the value.

    Throws

    Error if this number's units are incompatible with newNumerators and newDenominators.

    Parameters

    • newNumerators: string[] | List<string>

      The numerator units to convert this number to. This may be either a plain JavaScript array or an immutable List from the immutable package.

    • newDenominators: string[] | List<string>

      The denominator units to convert this number to. This may be either a plain JavaScript array or an immutable List from the immutable package.

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassNumber

    • Defined in js-api-doc/value/number.d.ts:223

coerceToMatch

  • coerceToMatch(other: SassNumber, name?: string, otherName?: string): SassNumber
  • Returns a copy of this number, converted to the units represented by newNumerators and newDenominators.

    Unlike convertToMatch this does not throw an error if this number is unitless and either newNumerators or newDenominators are not empty, or vice-versa. Instead, it treats all unitless numbers as convertible to and from all units without changing the value.

    Throws

    Error if this number's units are incompatible with other's units.

    Parameters

    • other: SassNumber
    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    • Optional otherName: string

      The name of the function argument other came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassNumber

    • Defined in js-api-doc/value/number.d.ts:247

coerceValue

  • coerceValue(newNumerators: string[] | List<string>, newDenominators: string[] | List<string>, name?: string): number
  • Returns value, converted to the units represented by newNumerators and newDenominators.

    Unlike convertValue this does not throw an error if this number is unitless and either newNumerators or newDenominators are not empty, or vice-versa. Instead, it treats all unitless numbers as convertible to and from all units without changing the value.

    Throws

    Error if this number's units are incompatible with newNumerators and newDenominators.

    Parameters

    • newNumerators: string[] | List<string>

      The numerator units to convert value to. This may be either a plain JavaScript array or an immutable List from the immutable package.

    • newDenominators: string[] | List<string>

      The denominator units to convert value to. This may be either a plain JavaScript array or an immutable List from the immutable package.

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns number

    • Defined in js-api-doc/value/number.d.ts:276

coerceValueToMatch

  • coerceValueToMatch(other: SassNumber, name?: string, otherName?: string): number
  • Returns value, converted to the units represented by newNumerators and newDenominators.

    Unlike convertValueToMatch this does not throw an error if this number is unitless and either newNumerators or newDenominators are not empty, or vice-versa. Instead, it treats all unitless numbers as convertible to and from all units without changing the value.

    Throws

    Error if this number's units are incompatible with other's units.

    Parameters

    • other: SassNumber
    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    • Optional otherName: string

      The name of the function argument other came from (without the $) if it came from an argument. Used for error reporting.

    Returns number

    • Defined in js-api-doc/value/number.d.ts:300

compatibleWithUnit

  • compatibleWithUnit(unit: string): boolean
  • Whether this has exactly one numerator unit, and that unit is compatible with unit.

    Parameters

    • unit: string

    Returns boolean

    • Defined in js-api-doc/value/number.d.ts:112

convert

  • convert(newNumerators: string[] | List<string>, newDenominators: string[] | List<string>, name?: string): SassNumber
  • Returns a copy of this number, converted to the units represented by newNumerators and newDenominators.

    Throws

    Error if this number's units are incompatible with newNumerators and newDenominators; or if this number is unitless and either newNumerators or newDenominators are not empty, or vice-versa.

    Parameters

    • newNumerators: string[] | List<string>

      The numerator units to convert this number to. This may be either a plain JavaScript array or an immutable List from the immutable package.

    • newDenominators: string[] | List<string>

      The denominator units to convert this number to. This may be either a plain JavaScript array or an immutable List from the immutable package.

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassNumber

    • Defined in js-api-doc/value/number.d.ts:133

convertToMatch

  • convertToMatch(other: SassNumber, name?: string, otherName?: string): SassNumber
  • Returns a copy of this number, converted to the same units as other.

    Throws

    Error if this number's units are incompatible with other's units, or if either number is unitless but the other is not.

    Parameters

    • other: SassNumber
    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    • Optional otherName: string

      The name of the function argument other came from (without the $) if it came from an argument. Used for error reporting.

    Returns SassNumber

    • Defined in js-api-doc/value/number.d.ts:151

convertValue

  • convertValue(newNumerators: string[] | List<string>, newDenominators: string[] | List<string>, name?: string): number
  • Returns value, converted to the units represented by newNumerators and newDenominators.

    Throws

    Error if this number's units are incompatible with newNumerators and newDenominators; or if this number is unitless and either newNumerators or newDenominators are not empty, or vice-versa.

    Parameters

    • newNumerators: string[] | List<string>

      The numerator units to convert value to. This may be either a plain JavaScript array or an immutable List from the immutable package.

    • newDenominators: string[] | List<string>

      The denominator units to convert value to. This may be either a plain JavaScript array or an immutable List from the immutable package.

    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    Returns number

    • Defined in js-api-doc/value/number.d.ts:176

convertValueToMatch

  • convertValueToMatch(other: SassNumber, name?: string, otherName?: string): number
  • Returns value, converted to the same units as other.

    Throws

    Error if this number's units are incompatible with other's units, or if either number is unitless but the other is not.

    Parameters

    • other: SassNumber
    • Optional name: string

      The name of the function argument this came from (without the $) if it came from an argument. Used for error reporting.

    • Optional otherName: string

      The name of the function argument other came from (without the $) if it came from an argument. Used for error reporting.

    Returns number

    • Defined in js-api-doc/value/number.d.ts:194

equals

  • equals(other: Value): boolean
  • Returns whether this represents the same value as other.

    Parameters

    • other: Value

    Returns boolean

    Inherited from Value.equals

    • Defined in js-api-doc/value/index.d.ts:212

get

  • get(index: number): undefined | Value
  • Returns the value at index index in this value as a list, or undefined if index isn't valid for this list.

    All SassScript values can be used as lists. Maps count as lists of pairs, and all other values count as single-value lists.

    This is a shorthand for this.asList.get(index), although it may be more efficient in some cases.

    This method uses the same indexing conventions as the immutable package: unlike Sass the index of the first element is 0, but like Sass negative numbers index from the end of the list.

    Parameters

    • index: number

    Returns undefined | Value

    Inherited from Value.get

    • Defined in js-api-doc/value/index.d.ts:136

hasUnit

  • hasUnit(unit: string): boolean
  • Whether this number has unit as its only unit (and as a numerator).

    Parameters

    • unit: string

    Returns boolean

    • Defined in js-api-doc/value/number.d.ts:106

hashCode

  • hashCode(): number
  • Returns a hash code that can be used to store this in a hash map.

    Returns number

    Inherited from Value.hashCode

    • Defined in js-api-doc/value/index.d.ts:215

sassIndexToListIndex

  • sassIndexToListIndex(sassIndex: Value, name?: string): number
  • Converts sassIndex into a JavaScript-style index into the list returned by asList.

    Sass indexes are one-based, while JavaScript indexes are zero-based. Sass indexes may also be negative in order to index from the end of the list.

    Throws

    Error If sassIndex isn't a number, if that number isn't an integer, or if that integer isn't a valid index for asList.

    Parameters

    • sassIndex: Value

      The Sass-style index into this as a list.

    • Optional name: string

      The name of the function argument sassIndex came from (without the $) if it came from an argument. Used for error reporting.

    Returns number

    Inherited from Value.sassIndexToListIndex

    • Defined in js-api-doc/value/index.d.ts:120

tryMap

  • tryMap(): null | SassMap
  • Returns this as a map if it counts as one (empty lists count as empty maps) or null if it doesn't.

    Returns null | SassMap

    Inherited from Value.tryMap

    • Defined in js-api-doc/value/index.d.ts:209
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/classes/SassNumber

Spec-Zone.ru

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