ni-data-types

1.3.0 • Public • Published

data-types Build Status

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 = new NIType('"Boolean"'); // A single boolean.
var arrayType = new NIType({name: 'Array', rank: 1, subtype:{name: 'Boolean'}}); // 1-D array of booleans.
 
var arraySubtype = arrayType.getSubtype(); // An instance of NIType
 
console.log(arraySubtype.isBoolean()); // true
console.log(booleanType.isBoolean()); // true
console.log(booleanType.equals(arraySubtype)); // true
console.log(booleanType.equals(arrayType)); // 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 = new NIComplex('1 + 2i');
var complex1 = new NIComplex(1, 2);
var complex2 = new NIComplex(1);
var wrongComplex = new NIComplex('not a number'); // will throw

Complex numbers are objects containing two IEEE754 numbers, realPart and imaginaryPart.

var complex = new NIComplex('1 + 2i');
var re = complex.realPart;
var im = complex.imaginaryPart;

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:

  1. the epoch used in NITimestamps is the LabVIEW epoch.
  2. the serialization format of the NITimestamp is using Int64, UInt64

Usage

var timestamp = new NITimestamp(); // the epoch
var timestamp2 = new NITimestamp('0:0'); // the epoch
var timestamp3 = new NITimestamp(new Date(Date.now())); // current time
var timestamp4 = new NITimestamp(35.27); // 35.27 seconds past the epoch
var timestamp5 = new NITimestamp(timestamp); // copy a timestamp

The NITimestamp constructor can be called with no parameters or with different types of parameters:

  1. 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
  1. a javascript Date
  2. a Number, representing the seconds passed since the epoch
  3. 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 = window.NIColorValueConverters.rgbaToInteger('rgb(237, 12, 140, 1)'); // Returns 4281020467
 
var hexColor = window.NIColorValueConverters.argbIntegerColorToRgbaHexColor(integerColor); // Returns "#ED0C8CFF"

Readme

Keywords

none

Package Sidebar

Install

npm i ni-data-types

Weekly Downloads

95

Version

1.3.0

License

https://www.ni.com/legal/license/

Unpacked Size

147 kB

Total Files

12

Last publish

Collaborators

  • ni-webapps-ops
  • prestwick