new (require("pete/lib/NanoTime"))(valueopt)
- Source:
Example
const NanoTime = require('pete/lib/nanotime');
var time = new NanoTime();
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
value |
number | bigint |
<optional> |
0n
|
Members
(static) MICROSECOND
- Description:
Value of one microsecond in nanoseconds.
- Source:
Value of one microsecond in nanoseconds.
(static) MILLISECOND
- Description:
Value of one millisecond in nanoseconds.
- Source:
Value of one millisecond in nanoseconds.
(static) NANOSECOND
- Description:
Value of nanosecond.
- Source:
Value of nanosecond.
(static) SECOND
- Description:
Value of one second in nanoseconds.
- Source:
Value of one second in nanoseconds.
Methods
get() → {bigint}
- Description:
Get number of nanoseconds.
- Source:
Example
var time = new NanoTime(process.hrtime.bigint());
console.log(time.get()); // 1002003004n
Returns:
- Type
- bigint
set(value) → {module:lib/nanotime~NanoTime|any}
- Description:
Set new value.
- Source:
- See:
-
- NanoTime.from
Parameters:
| Name | Type | Description |
|---|---|---|
value |
string | number | bigint | module:lib/nanotime~NanoTime |
Returns:
- Type
- module:lib/nanotime~NanoTime | any
toJSON() → {string}
- Description:
When stringified to JSON, output String representation instead of full object.
- Source:
- See:
Example
var time = new NanoTime(process.hrtime.bigint());
console.log(JSON.stringify(time)); // "1m 2s 3ms 4μs 5ns"
Returns:
- Type
- string
toNumber() → {number}
- Description:
Convert to Number.
- Source:
Example
var time = new NanoTime(process.hrtime.bigint());
console.log(time.toNumber()); // 1.002003004
Returns:
- Type
- number
toString() → {string}
- Description:
Convert to textual representation of value.
- Source:
- See:
Example
var time = new NanoTime(process.hrtime.bigint());
console.log(time); // 1m 2s 3ms 4μs 5ns
Returns:
- Type
- string
valueOf() → {bigint}
- Description:
Get number of nanoseconds.
- Source:
- See:
Returns:
- Type
- bigint
(static) from(value) → {module:lib/nanotime~NanoTime|any}
- Description:
Create NanoTime from value.
If called on existing NanoTime object, it will update its value instead of creating new object.
If value type is not supported, simply return that value.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | bigint | string | module:lib/nanotime~NanoTime |
Returns:
- Type
- module:lib/nanotime~NanoTime | any