Function wrapper for creating new Numbr instances, it also has useful static methods to
control the global module behaviour.
Classes
Members
-
(static) echoConsumer :Consumer
-
A simple consumer that echoes back as many characters as possible in one step. This is the default consumer.
Type:
- Consumer
-
(static) noopConsumer :Consumer
-
A simple consumer that consumes the single character is given and does nothing else. You can set this consumer as the default by using numbr.setDefaultConsumer
Type:
- Consumer
Methods
-
(static) addConsumer(consumer)
-
Adds a consumer to the list of global consumers. Consumers are used to translate the string format input into actual transforming steps.
Parameters:
Name Type Description consumerConsumer -
(static) cacheEnabled(enabled)
-
Enables or disables the format cache. By default every format is compiled into a series of transformation functions that are cached and reused every time Numbr.format is called. Disabling the cache may cause a significant performance hit and it is not recommended. Most applications will probably use just a handful of formats, so the memory overhead is non-existent.
Parameters:
Name Type Description enabledboolean Whether to enable or disable the cache -
(static) compile(fmt) → {CompiledFormat}
-
Compiles the given string into a CompiledFormat object ready to be used.
Parameters:
Name Type Description fmtstring Returns:
- Type
- CompiledFormat
-
(static) defaultFormat(fmt)
-
Sets the default format. The default format is used if Numbr#format is called without arguments.
Parameters:
Name Type Description fmt -
(static) language(langCodeopt, langDefopt)
-
Gets the global language, sets the global language or loads a language. If called with no arguments, returns the global language. If called with just the language code, it sets the global language. If called with both arguments, the language is just loaded.
Parameters:
Name Type Attributes Description langCodestring <optional>
The language code langDefobject <optional>
A valid language definition -
(static) setDefaultConsumer(consumer)
-
Sets the default consumer. The default consumer is used when no other consumer is able to consume a slice of the input format string. By default, this is numbr.echoConsumer.
Parameters:
Name Type Description consumer -
(static) setGlobalLang(langCode)
-
Sets the global language.
Parameters:
Name Type Description langCode -
(static) zeroFormat(fmt)
-
Sets the global zero format. If defined, the zero format is used as the outout of Numbr#format whenever the wrapped value === 0.
Parameters:
Name Type Description fmt