Integer

Path: /src/type/integer.coffee compiled to /lib/type/integer.js

This will check an integer number against a precise definition in which range it may be.

Sanitize options allowed:

  • sanitize - Boolean remove invalid characters
  • unit - String unit to convert to if no number is given
  • round - Boolean|String rounding of float can be set to true for arithmetic rounding or use floor or ceil for the corresponding methods

Check options:

  • min - Integer the smallest allowed number
  • max - Integer the biggest allowed number
  • inttype - Integer|String the integer is of given type (4, 8, 16, 32, 64, ‘byte’, ‘short’,‘long’,‘quad’, ‘safe’)
  • unsigned - Boolean the integer has to be positive

Format options:

  • toUnit - String unit to convert value to
  • format - String format number as string
  • ‘locale’ - String locale format to use for string output

The result will be a Number or String representation of a number depending on the above parameters.

Additional Possibilities

Use theOr type to allow multiple ranges.

Alternative Number Checks

You may also use: -Float -Percent -Byte

Schema Specification

Float is a float schema definition.

An object with the following keys allowed: sanitize, unit, round, inttype, unsigned, min, max, toUnit, format, locale, title, description, key, type, optional, default. The following entries have a specific format:

sanitize

Sanitize is a flag which allows removing of non numeric characters before evaluating.

A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.

unit

Source Unit is the unit in which an only numeric value is given, will transform to base unit.

A text entry which is optional. All control characters will be removed. It has to be at least 1 characters long.

round

Rounding is the value can be rounded in different ways.

It has to be one of the following types (optional):

  • Arithmetic Rounding is a flag which allows arithmetic rounding (till 4 down, from 5 up) if set to true.

    A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false.

  • Alternative Rounding is the alternative rounding method to be used.

    A text entry in which all control characters will be removed. Only the values: ‘floor’, ‘ceil’ are allowed.

inttype

Integer Type is the type (size) of the allowed integer.

It has to be one of the following types (optional):

  • Byte Size is the type of the integer as mnumber of bytes.

    An integer value.

  • Named Type is the named type (size) of the integer.

    A text entry in which all control characters will be removed. Only the values: ‘byte’, ‘short’, ‘long’, ‘quad’, ‘safe’ are allowed.

unsigned

Unsigned is a setting to allow only signed false or unsigned integers true.

A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.

min

Min Value is the minimal value to be set.

A numeric floating point number which is optional.

max

Max Value is the maximal value to be set.

A numeric floating point number which is optional. The value should be greater than <<>>.

toUnit

Result Unit is the unit to which to transform the value.

A text entry which is optional. All control characters will be removed.

format

Format is the numerical output format to use.

A text entry which is optional. All control characters will be removed.

locale

Locale is the language to be used for locale specific number format.

A text entry which is optional. All control characters will be removed. The text should match: /[1](?:-[A-Z]{2})?$/.

title

Title is the title used to describe the element.

A text entry which is optional. All control characters will be removed.

description

Description is the free description of the element.

A text entry which is optional. All control characters will be removed.

key

Binding to Keyname is the mapping to which key names in an object this element belongs.

A valid regular expression which is optional. It has to be one of the following types:

  • An object which has to be an instance of class RegExp.
  • A text entry in which all control characters will be removed. The text should match: /^/.?/[gim]$/.
type

Type is the type of element.

A text entry in which all control characters will be removed.

optional

Optional is a flag defining if this element is optional.

A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.

default

Default Value is the default value to use if nothing given.

An integer value which is optional.


  1. a-z ↩︎