data-types
This repository contains support for non-standard Javascript data types needed for engineering and scientific applications.
Data Types
NIType
Contains all the information needed to fully describe a NIType, as as an API to retrieve the information. It can be constructed from a JSON encoded string or a full notation object.
var booleanType = '"Boolean"'; // A single boolean.var arrayType = name: 'Array' rank: 1 subtype:name: 'Boolean'; // 1-D array of booleans. var arraySubtype = arrayType; // An instance of NIType console; // trueconsole; // trueconsole; // trueconsole; // false
For more information, you can look at the docs of NIType.
NIComplex. Complex numbers for high performance applications
Can be constructed from a string representing
- complex numbers with real part before imaginary part or imaginary part before real part
- complex numbers represented with scientific notation
- complex numbers whose real and/or imaginary parts contain metric (SI) prefixes, such as kilo (k) or mega (M).
- complex numbers with only real or imaginary part
- complex numbers containing NaN as imaginary part, real part, or both
- +/-infinity, +/-inf, +/-Infinity, +/-Inf
- complex numbers that have the imaginary part represented only as +/-i or i
Can be constructed from numbers
- first paramater value is used for the real part and the second one for the imaginary part
It throw errors for any type of invalid input
var complex = '1 + 2i';var complex1 = 1 2;var complex2 = 1;var wrongComplex = 'not a number'; // will throw
Complex numbers are objects containing two IEEE754 numbers, realPart and imaginaryPart.
var complex = '1 + 2i';var re = complexrealPart;var im = compleximaginaryPart;
NITimestamp. High precision timestamps
A NITimestamp is a data structure used to represent time with the high precision needed by scientific and engineering applications. An NITimestamp is composed by a pair of:
- seconds, a integer number representing seconds passed since the epoch
- fractions, an integer number between 0 and 252 - 1 representing the fractions of seconds in the timestamp. A fraction is one second divided by 252.
The main design goals of the NITimestamp is interoperability with LabVIEW Timestamp, and as a consequence:
- the epoch used in NITimestamps is the LabVIEW epoch.
- the serialization format of the NITimestamp is using Int64, UInt64
Usage
var timestamp = ; // the epochvar timestamp2 = '0:0'; // the epochvar timestamp3 = Date; // current timevar timestamp4 = 3527; // 35.27 seconds past the epochvar timestamp5 = timestamp; // copy a timestamp
The NITimestamp constructor can be called with no parameters or with different types of parameters:
- a string in the format "123:567890" where
- the first part is an INT64 serialized to a decimal string, representing the nr. of seconds relative to epoch
- the second part is a UINT64 serialized to a decimal string, representing the fractional part of the seconds
- a javascript Date
- a Number, representing the seconds passed since the epoch
- a NITimestamp.
NIAnalogWaveform. A waveform of analog data samples
A NIAnalogWaveform represents a series of analog data samples. The main use case for it is for samples acquired periodically with a constant time interval between them.
NIColorValueConverters. Converters for several color formats
A NIColorValueConverters has static functions that allow conversion between formats like RGBA, ARGB and hexadecimal.
Usage
var integerColor = windowNIColorValueConverters; // Returns 4281020467 var hexColor = windowNIColorValueConverters; // Returns "#ED0C8CFF"