influx 5.0.3 → 5.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,318 +1,325 @@
1
- "use strict";
2
- var ds_1 = require('./ds');
3
- /**
4
- * Just a quick overview of what's going on in this file. It's a bit of a mess.
5
- * Influx uses three time formats:
6
- * - ISO times with nanoseconds when querying where an epoch is not provided
7
- * - Unix timestamps when querying with an epoch (specifying the precision
8
- * in the given time unit)
9
- * - Its own time format for time literals.
10
- *
11
- * To complicate matters, Influx operates on nanosecond precisions
12
- * by default, but we can't represent nanosecond timestamps in
13
- * JavaScript numbers as they're 64 bit uints.
14
- *
15
- * As a result we have several utilities to convert between these different
16
- * formats. When precision is required, we represent nanosecond timestamps
17
- * as strings and wrap default dates in the INanoDate interface which
18
- * lets the consumer read and write these more precise timestamps.
19
- *
20
- * Representing the timestamps as strings is definitely not a pure way to go
21
- * about it, but importing an arbitrary-precision integer library adds
22
- * bloat and is a massive hit to throughput. The operations we do do
23
- * are pretty trivial, so we stick with manipulating strings
24
- * and make sure to wash our hands when we're done.
25
- *
26
- * Vocabulary:
27
- * Unix timestamp = 'timestamp', abbreviated as 'time'
28
- * ISO timestamp = 'ISO time', abbreviated as 'ISO'
29
- * Influx timestamp = 'Influx time', abbreviated as 'Influx'
30
- */
31
- function leftPad(str, length, pad) {
32
- if (pad === void 0) { pad = '0'; }
33
- if (typeof str === 'number') {
34
- str = String(str);
35
- }
36
- while (str.length < length) {
37
- str = pad + str;
38
- }
39
- return str;
40
- }
41
- function rightPad(str, length, pad) {
42
- if (pad === void 0) { pad = '0'; }
43
- if (typeof str === 'number') {
44
- str = String(str);
45
- }
46
- while (str.length < length) {
47
- str += pad;
48
- }
49
- return str;
50
- }
51
- /**
52
- * Precision is a map of available Influx time precisions.
53
- * @type {Object.<String, String>}
54
- * @example
55
- * console.log(Precision.Hours); // => 'h'
56
- * console.log(Precision.Minutes); // => 'm'
57
- * console.log(Precision.Seconds); // => 's'
58
- * console.log(Precision.Milliseconds); // => 'ms'
59
- * console.log(Precision.Microseconds); // => 'u'
60
- * console.log(Precision.Nanoseconds); // => 'ns'
61
- */
62
- exports.Precision = Object.freeze({
63
- Hours: 'h',
64
- Microseconds: 'u',
65
- Milliseconds: 'ms',
66
- Minutes: 'm',
67
- Nanoseconds: 'n',
68
- Seconds: 's',
69
- });
70
- var MillisecondDateManipulator = (function () {
71
- function MillisecondDateManipulator() {
72
- }
73
- MillisecondDateManipulator.prototype.format = function (date) {
74
- return '"' + leftPad(date.getUTCFullYear(), 2)
75
- + '-' + leftPad(date.getUTCMonth() + 1, 2)
76
- + '-' + leftPad(date.getUTCDate(), 2)
77
- + ' ' + leftPad(date.getUTCHours(), 2)
78
- + ':' + leftPad(date.getUTCMinutes(), 2)
79
- + ':' + leftPad(date.getUTCSeconds(), 2)
80
- + '.' + leftPad(date.getUTCMilliseconds(), 3) + '"';
81
- };
82
- MillisecondDateManipulator.prototype.toTime = function (date, precision) {
83
- var ms = date.getTime();
84
- switch (precision) {
85
- case 'n':
86
- ms *= 1000;
87
- case 'u':
88
- ms *= 1000;
89
- case 'ms':
90
- return String(ms);
91
- case 'h':
92
- ms /= 60;
93
- case 'm':
94
- ms /= 60;
95
- case 's':
96
- ms /= 1000;
97
- return String(Math.floor(ms));
98
- default:
99
- throw new Error("Unknown precision '" + precision + "'!");
100
- }
101
- };
102
- MillisecondDateManipulator.prototype.isoToDate = function (timestamp) {
103
- return new Date(timestamp);
104
- };
105
- MillisecondDateManipulator.prototype.timetoDate = function (timestamp, precision) {
106
- switch (precision) {
107
- case 'n':
108
- timestamp /= 1000;
109
- case 'u':
110
- timestamp /= 1000;
111
- case 'ms':
112
- return new Date(timestamp);
113
- case 'h':
114
- timestamp *= 60;
115
- case 'm':
116
- timestamp *= 60;
117
- case 's':
118
- timestamp *= 1000;
119
- return new Date(timestamp);
120
- default:
121
- throw new Error("Unknown precision '" + precision + "'!");
122
- }
123
- };
124
- return MillisecondDateManipulator;
125
- }());
126
- var nsPer = {
127
- ms: Math.pow(10, 6),
128
- s: Math.pow(10, 9),
129
- };
130
- function nanoIsoToTime(iso) {
131
- var _a = iso.split('.'), secondsStr = _a[0], decimalStr = _a[1];
132
- var seconds = Math.floor(new Date(secondsStr + 'Z').getTime() / 1000);
133
- var decimal = rightPad(decimalStr.slice(0, -1), 9);
134
- return "" + seconds + decimal;
135
- }
136
- var nanoDateMethods = {
137
- getNanoTimeFromISO: function () {
138
- if (!this._cachedNanoISO) {
139
- this._cachedNanoTime = nanoIsoToTime(this._nanoISO);
140
- }
141
- return this._cachedNanoTime;
142
- },
143
- toNanoISOStringFromISO: function () {
144
- if (!this._cachedNanoISO) {
145
- this._cachedNanoTime = nanoIsoToTime(this._nanoISO);
146
- }
147
- var base = this.toISOString().slice(0, -4); // slice of `123Z` milliseconds
148
- return "" + base + this._cachedNanoTime.slice(-9) + "Z";
149
- },
150
- getNanoTimeFromStamp: function () {
151
- return this._nanoTime;
152
- },
153
- toNanoISOStringFromStamp: function () {
154
- var base = this.toISOString().slice(0, -4); // slice of `123Z` milliseconds
155
- return "" + base + this._nanoTime.slice(-9) + "Z";
156
- },
157
- };
158
- /**
159
- * Covers a nanoseconds unix timestamp to a INanoDate for node-influx. The
160
- * timestamp is provided as a string to prevent precision loss.
161
- *
162
- * Please see [A Moment for Times](https://node-influx.github.io/manual/
163
- * usage.html#a-moment-for-times) for a more complete and eloquent explanation
164
- * of time handling in this module.
165
- *
166
- * @param {String} timestamp
167
- * @returns {INanoDate}
168
- * @example
169
- * const date = toNanoDate('1475985480231035600')
170
- *
171
- * // You can use the returned Date as a normal date:
172
- * expect(date.getTime()).to.equal(1475985480231);
173
- *
174
- * // We decorate it with two additional methods to read
175
- * // nanosecond-precision results:
176
- * expect(date.getNanoTime()).to.equal('1475985480231035600');
177
- * expect(date.toNanoISOString()).to.equal('2016-10-09T03:58:00.231035600Z');
178
- */
179
- function toNanoDate(timestamp) {
180
- var date = new Date(Math.floor(Number(timestamp) / nsPer.ms));
181
- date._nanoTime = timestamp;
182
- date.getNanoTime = nanoDateMethods.getNanoTimeFromStamp;
183
- date.toNanoISOString = nanoDateMethods.toNanoISOStringFromStamp;
184
- return date;
185
- }
186
- exports.toNanoDate = toNanoDate;
187
- function asNanoDate(date) {
188
- var d = date;
189
- if (d.getNanoTime) {
190
- return d;
191
- }
192
- return undefined;
193
- }
194
- var NanosecondsDateManipulator = (function () {
195
- function NanosecondsDateManipulator() {
196
- }
197
- NanosecondsDateManipulator.prototype.format = function (date) {
198
- return '"' + leftPad(date.getUTCFullYear(), 2)
199
- + '-' + leftPad(date.getUTCMonth() + 1, 2)
200
- + '-' + leftPad(date.getUTCDate(), 2)
201
- + ' ' + leftPad(date.getUTCHours(), 2)
202
- + ':' + leftPad(date.getUTCMinutes(), 2)
203
- + ':' + leftPad(date.getUTCSeconds(), 2)
204
- + '.' + date.getNanoTime().slice(-9) + '"';
205
- };
206
- NanosecondsDateManipulator.prototype.toTime = function (date, precision) {
207
- var ms = date.getTime();
208
- switch (precision) {
209
- case 'u':
210
- return date.getNanoTime().slice(0, -3);
211
- case 'n':
212
- return date.getNanoTime();
213
- case 'h':
214
- ms /= 60;
215
- case 'm':
216
- ms /= 60;
217
- case 's':
218
- ms /= 1000;
219
- case 'ms':
220
- return String(Math.floor(ms));
221
- default:
222
- throw new Error("Unknown precision '" + precision + "'!");
223
- }
224
- };
225
- NanosecondsDateManipulator.prototype.isoToDate = function (timestamp) {
226
- var date = new Date(timestamp);
227
- date._nanoISO = timestamp;
228
- date.getNanoTime = nanoDateMethods.getNanoTimeFromISO;
229
- date.toNanoISOString = nanoDateMethods.toNanoISOStringFromISO;
230
- return date;
231
- };
232
- NanosecondsDateManipulator.prototype.timetoDate = function (timestamp, precision) {
233
- switch (precision) {
234
- case 'h':
235
- timestamp *= 60;
236
- case 'm':
237
- timestamp *= 60;
238
- case 's':
239
- timestamp *= 1000;
240
- case 'ms':
241
- timestamp *= 1000;
242
- case 'u':
243
- timestamp *= 1000;
244
- case 'n':
245
- var date = new Date(timestamp / nsPer.ms);
246
- date._nanoTime = String(timestamp);
247
- date.getNanoTime = nanoDateMethods.getNanoTimeFromStamp;
248
- date.toNanoISOString = nanoDateMethods.toNanoISOStringFromStamp;
249
- return date;
250
- default:
251
- throw new Error("Unknown precision '" + precision + "'!");
252
- }
253
- };
254
- return NanosecondsDateManipulator;
255
- }());
256
- var milliManipulator = new MillisecondDateManipulator();
257
- var nanoManipulator = new NanosecondsDateManipulator();
258
- /**
259
- * formatDate converts the Date instance to Influx's date query format.
260
- * @private
261
- */
262
- function formatDate(date) {
263
- var nano = asNanoDate(date);
264
- if (nano) {
265
- return nanoManipulator.format(nano);
266
- }
267
- else {
268
- return milliManipulator.format(date);
269
- }
270
- }
271
- exports.formatDate = formatDate;
272
- /**
273
- * Converts a Date instance to a timestamp with the specified time precision.
274
- * @private
275
- */
276
- function dateToTime(date, precision) {
277
- var nano = asNanoDate(date);
278
- if (nano) {
279
- return nanoManipulator.toTime(nano, precision);
280
- }
281
- else {
282
- return milliManipulator.toTime(date, precision);
283
- }
284
- }
285
- exports.dateToTime = dateToTime;
286
- /**
287
- * Converts an ISO-formatted data or unix timestamp to a Date instance. If
288
- * the precision is finer than 'ms' the returned value will be a INanoDate.
289
- * @private
290
- */
291
- function isoOrTimeToDate(stamp, precision) {
292
- if (precision === void 0) { precision = 'n'; }
293
- if (typeof stamp === 'string') {
294
- return nanoManipulator.isoToDate(stamp);
295
- }
296
- else {
297
- return nanoManipulator.timetoDate(stamp, precision);
298
- }
299
- }
300
- exports.isoOrTimeToDate = isoOrTimeToDate;
301
- /**
302
- * Converts a timestamp to a string with the correct precision. Assumes
303
- * that raw number and string instances are already in the correct precision.
304
- * @private
305
- */
306
- function castTimestamp(timestamp, precision) {
307
- if (typeof timestamp === 'string') {
308
- if (!ds_1.isNumeric(timestamp)) {
309
- throw new Error("Expected numeric value for, timestamp, but got '" + timestamp + "'!");
310
- }
311
- return timestamp;
312
- }
313
- if (typeof timestamp === 'number') {
314
- return String(timestamp);
315
- }
316
- return dateToTime(timestamp, precision);
317
- }
318
- exports.castTimestamp = castTimestamp;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var ds_1 = require("./ds");
4
+ /**
5
+ * Just a quick overview of what's going on in this file. It's a bit of a mess.
6
+ * Influx uses three time formats:
7
+ * - ISO times with nanoseconds when querying where an epoch is not provided
8
+ * - Unix timestamps when querying with an epoch (specifying the precision
9
+ * in the given time unit)
10
+ * - Its own time format for time literals.
11
+ *
12
+ * To complicate matters, Influx operates on nanosecond precisions
13
+ * by default, but we can't represent nanosecond timestamps in
14
+ * JavaScript numbers as they're 64 bit uints.
15
+ *
16
+ * As a result we have several utilities to convert between these different
17
+ * formats. When precision is required, we represent nanosecond timestamps
18
+ * as strings and wrap default dates in the INanoDate interface which
19
+ * lets the consumer read and write these more precise timestamps.
20
+ *
21
+ * Representing the timestamps as strings is definitely not a pure way to go
22
+ * about it, but importing an arbitrary-precision integer library adds
23
+ * bloat and is a massive hit to throughput. The operations we do do
24
+ * are pretty trivial, so we stick with manipulating strings
25
+ * and make sure to wash our hands when we're done.
26
+ *
27
+ * Vocabulary:
28
+ * Unix timestamp = 'timestamp', abbreviated as 'time'
29
+ * ISO timestamp = 'ISO time', abbreviated as 'ISO'
30
+ * Influx timestamp = 'Influx time', abbreviated as 'Influx'
31
+ */
32
+ function leftPad(str, length, pad) {
33
+ if (pad === void 0) { pad = '0'; }
34
+ if (typeof str === 'number') {
35
+ str = String(str);
36
+ }
37
+ while (str.length < length) {
38
+ str = pad + str;
39
+ }
40
+ return str;
41
+ }
42
+ function rightPad(str, length, pad) {
43
+ if (pad === void 0) { pad = '0'; }
44
+ if (typeof str === 'number') {
45
+ str = String(str);
46
+ }
47
+ while (str.length < length) {
48
+ str += pad;
49
+ }
50
+ return str;
51
+ }
52
+ /**
53
+ * Precision is a map of available Influx time precisions.
54
+ * @type {Object.<String, String>}
55
+ * @example
56
+ * console.log(Precision.Hours); // => 'h'
57
+ * console.log(Precision.Minutes); // => 'm'
58
+ * console.log(Precision.Seconds); // => 's'
59
+ * console.log(Precision.Milliseconds); // => 'ms'
60
+ * console.log(Precision.Microseconds); // => 'u'
61
+ * console.log(Precision.Nanoseconds); // => 'ns'
62
+ */
63
+ exports.Precision = Object.freeze({
64
+ Hours: 'h',
65
+ Microseconds: 'u',
66
+ Milliseconds: 'ms',
67
+ Minutes: 'm',
68
+ Nanoseconds: 'n',
69
+ Seconds: 's',
70
+ });
71
+ var MillisecondDateManipulator = (function () {
72
+ function MillisecondDateManipulator() {
73
+ }
74
+ MillisecondDateManipulator.prototype.format = function (date) {
75
+ return '"' + leftPad(date.getUTCFullYear(), 2)
76
+ + '-' + leftPad(date.getUTCMonth() + 1, 2)
77
+ + '-' + leftPad(date.getUTCDate(), 2)
78
+ + ' ' + leftPad(date.getUTCHours(), 2)
79
+ + ':' + leftPad(date.getUTCMinutes(), 2)
80
+ + ':' + leftPad(date.getUTCSeconds(), 2)
81
+ + '.' + leftPad(date.getUTCMilliseconds(), 3) + '"';
82
+ };
83
+ MillisecondDateManipulator.prototype.toTime = function (date, precision) {
84
+ var ms = date.getTime();
85
+ switch (precision) {
86
+ case 'n':
87
+ ms *= 1000;
88
+ case 'u':
89
+ ms *= 1000;
90
+ case 'ms':
91
+ return String(ms);
92
+ case 'h':
93
+ ms /= 60;
94
+ case 'm':
95
+ ms /= 60;
96
+ case 's':
97
+ ms /= 1000;
98
+ return String(Math.floor(ms));
99
+ default:
100
+ throw new Error("Unknown precision '" + precision + "'!");
101
+ }
102
+ };
103
+ MillisecondDateManipulator.prototype.isoToDate = function (timestamp) {
104
+ return new Date(timestamp);
105
+ };
106
+ MillisecondDateManipulator.prototype.timetoDate = function (timestamp, precision) {
107
+ switch (precision) {
108
+ case 'n':
109
+ timestamp /= 1000;
110
+ case 'u':
111
+ timestamp /= 1000;
112
+ case 'ms':
113
+ return new Date(timestamp);
114
+ case 'h':
115
+ timestamp *= 60;
116
+ case 'm':
117
+ timestamp *= 60;
118
+ case 's':
119
+ timestamp *= 1000;
120
+ return new Date(timestamp);
121
+ default:
122
+ throw new Error("Unknown precision '" + precision + "'!");
123
+ }
124
+ };
125
+ return MillisecondDateManipulator;
126
+ }());
127
+ var nsPer = {
128
+ ms: Math.pow(10, 6),
129
+ s: Math.pow(10, 9),
130
+ };
131
+ function nanoIsoToTime(iso) {
132
+ var _a = iso.split('.'), secondsStr = _a[0], decimalStr = _a[1];
133
+ if (decimalStr === undefined) {
134
+ decimalStr = '000000000';
135
+ }
136
+ else {
137
+ decimalStr = rightPad(decimalStr.slice(0, -1), 9);
138
+ secondsStr += 'Z';
139
+ }
140
+ var seconds = Math.floor(new Date(secondsStr).getTime() / 1000);
141
+ return "" + seconds + decimalStr;
142
+ }
143
+ var nanoDateMethods = {
144
+ getNanoTimeFromISO: function () {
145
+ if (!this._cachedNanoISO) {
146
+ this._cachedNanoTime = nanoIsoToTime(this._nanoISO);
147
+ }
148
+ return this._cachedNanoTime;
149
+ },
150
+ toNanoISOStringFromISO: function () {
151
+ if (!this._cachedNanoISO) {
152
+ this._cachedNanoTime = nanoIsoToTime(this._nanoISO);
153
+ }
154
+ var base = this.toISOString().slice(0, -4); // slice of `123Z` milliseconds
155
+ return "" + base + this._cachedNanoTime.slice(-9) + "Z";
156
+ },
157
+ getNanoTimeFromStamp: function () {
158
+ return this._nanoTime;
159
+ },
160
+ toNanoISOStringFromStamp: function () {
161
+ var base = this.toISOString().slice(0, -4); // slice of `123Z` milliseconds
162
+ return "" + base + this._nanoTime.slice(-9) + "Z";
163
+ },
164
+ };
165
+ /**
166
+ * Covers a nanoseconds unix timestamp to a INanoDate for node-influx. The
167
+ * timestamp is provided as a string to prevent precision loss.
168
+ *
169
+ * Please see [A Moment for Times](https://node-influx.github.io/manual/
170
+ * usage.html#a-moment-for-times) for a more complete and eloquent explanation
171
+ * of time handling in this module.
172
+ *
173
+ * @param {String} timestamp
174
+ * @returns {INanoDate}
175
+ * @example
176
+ * const date = toNanoDate('1475985480231035600')
177
+ *
178
+ * // You can use the returned Date as a normal date:
179
+ * expect(date.getTime()).to.equal(1475985480231);
180
+ *
181
+ * // We decorate it with two additional methods to read
182
+ * // nanosecond-precision results:
183
+ * expect(date.getNanoTime()).to.equal('1475985480231035600');
184
+ * expect(date.toNanoISOString()).to.equal('2016-10-09T03:58:00.231035600Z');
185
+ */
186
+ function toNanoDate(timestamp) {
187
+ var date = new Date(Math.floor(Number(timestamp) / nsPer.ms));
188
+ date._nanoTime = timestamp;
189
+ date.getNanoTime = nanoDateMethods.getNanoTimeFromStamp;
190
+ date.toNanoISOString = nanoDateMethods.toNanoISOStringFromStamp;
191
+ return date;
192
+ }
193
+ exports.toNanoDate = toNanoDate;
194
+ function asNanoDate(date) {
195
+ var d = date;
196
+ if (d.getNanoTime) {
197
+ return d;
198
+ }
199
+ return undefined;
200
+ }
201
+ var NanosecondsDateManipulator = (function () {
202
+ function NanosecondsDateManipulator() {
203
+ }
204
+ NanosecondsDateManipulator.prototype.format = function (date) {
205
+ return '"' + leftPad(date.getUTCFullYear(), 2)
206
+ + '-' + leftPad(date.getUTCMonth() + 1, 2)
207
+ + '-' + leftPad(date.getUTCDate(), 2)
208
+ + ' ' + leftPad(date.getUTCHours(), 2)
209
+ + ':' + leftPad(date.getUTCMinutes(), 2)
210
+ + ':' + leftPad(date.getUTCSeconds(), 2)
211
+ + '.' + date.getNanoTime().slice(-9) + '"';
212
+ };
213
+ NanosecondsDateManipulator.prototype.toTime = function (date, precision) {
214
+ var ms = date.getTime();
215
+ switch (precision) {
216
+ case 'u':
217
+ return date.getNanoTime().slice(0, -3);
218
+ case 'n':
219
+ return date.getNanoTime();
220
+ case 'h':
221
+ ms /= 60;
222
+ case 'm':
223
+ ms /= 60;
224
+ case 's':
225
+ ms /= 1000;
226
+ case 'ms':
227
+ return String(Math.floor(ms));
228
+ default:
229
+ throw new Error("Unknown precision '" + precision + "'!");
230
+ }
231
+ };
232
+ NanosecondsDateManipulator.prototype.isoToDate = function (timestamp) {
233
+ var date = new Date(timestamp);
234
+ date._nanoISO = timestamp;
235
+ date.getNanoTime = nanoDateMethods.getNanoTimeFromISO;
236
+ date.toNanoISOString = nanoDateMethods.toNanoISOStringFromISO;
237
+ return date;
238
+ };
239
+ NanosecondsDateManipulator.prototype.timetoDate = function (timestamp, precision) {
240
+ switch (precision) {
241
+ case 'h':
242
+ timestamp *= 60;
243
+ case 'm':
244
+ timestamp *= 60;
245
+ case 's':
246
+ timestamp *= 1000;
247
+ case 'ms':
248
+ timestamp *= 1000;
249
+ case 'u':
250
+ timestamp *= 1000;
251
+ case 'n':
252
+ var date = new Date(timestamp / nsPer.ms);
253
+ date._nanoTime = String(timestamp);
254
+ date.getNanoTime = nanoDateMethods.getNanoTimeFromStamp;
255
+ date.toNanoISOString = nanoDateMethods.toNanoISOStringFromStamp;
256
+ return date;
257
+ default:
258
+ throw new Error("Unknown precision '" + precision + "'!");
259
+ }
260
+ };
261
+ return NanosecondsDateManipulator;
262
+ }());
263
+ var milliManipulator = new MillisecondDateManipulator();
264
+ var nanoManipulator = new NanosecondsDateManipulator();
265
+ /**
266
+ * formatDate converts the Date instance to Influx's date query format.
267
+ * @private
268
+ */
269
+ function formatDate(date) {
270
+ var nano = asNanoDate(date);
271
+ if (nano) {
272
+ return nanoManipulator.format(nano);
273
+ }
274
+ else {
275
+ return milliManipulator.format(date);
276
+ }
277
+ }
278
+ exports.formatDate = formatDate;
279
+ /**
280
+ * Converts a Date instance to a timestamp with the specified time precision.
281
+ * @private
282
+ */
283
+ function dateToTime(date, precision) {
284
+ var nano = asNanoDate(date);
285
+ if (nano) {
286
+ return nanoManipulator.toTime(nano, precision);
287
+ }
288
+ else {
289
+ return milliManipulator.toTime(date, precision);
290
+ }
291
+ }
292
+ exports.dateToTime = dateToTime;
293
+ /**
294
+ * Converts an ISO-formatted data or unix timestamp to a Date instance. If
295
+ * the precision is finer than 'ms' the returned value will be a INanoDate.
296
+ * @private
297
+ */
298
+ function isoOrTimeToDate(stamp, precision) {
299
+ if (precision === void 0) { precision = 'n'; }
300
+ if (typeof stamp === 'string') {
301
+ return nanoManipulator.isoToDate(stamp);
302
+ }
303
+ else {
304
+ return nanoManipulator.timetoDate(stamp, precision);
305
+ }
306
+ }
307
+ exports.isoOrTimeToDate = isoOrTimeToDate;
308
+ /**
309
+ * Converts a timestamp to a string with the correct precision. Assumes
310
+ * that raw number and string instances are already in the correct precision.
311
+ * @private
312
+ */
313
+ function castTimestamp(timestamp, precision) {
314
+ if (typeof timestamp === 'string') {
315
+ if (!ds_1.isNumeric(timestamp)) {
316
+ throw new Error("Expected numeric value for, timestamp, but got '" + timestamp + "'!");
317
+ }
318
+ return timestamp;
319
+ }
320
+ if (typeof timestamp === 'number') {
321
+ return String(timestamp);
322
+ }
323
+ return dateToTime(timestamp, precision);
324
+ }
325
+ exports.castTimestamp = castTimestamp;