@steerprotocol/app-loader 2.0.0 → 2.1.1

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.
package/lib/Candle.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateCandles = exports.decodeCandle = exports.encodeCandle = exports.Candle = void 0;
7
- const timestring_1 = __importDefault(require("timestring"));
7
+ const timestring_1 = __importDefault(require("./timestring"));
8
8
  class Candle {
9
9
  constructor(timestamp, high, low, open, close, volume) {
10
10
  this.timestamp = timestamp;
package/lib/esm/Candle.js CHANGED
@@ -1,4 +1,4 @@
1
- import timestring from 'timestring';
1
+ import timestring from './timestring';
2
2
  export class Candle {
3
3
  timestamp;
4
4
  high;
package/lib/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ethers } from 'ethers';
2
2
  import { Candle, generateCandles } from './Candle';
3
3
  import { RawTradeData } from './RawTradeData';
4
- let isNode = process || null;
4
+ const isNode = typeof window === 'undefined' && typeof process !== 'undefined';
5
5
  let fetchImpl = null;
6
6
  let fsImpl = null;
7
7
  let ccxt = null;
@@ -0,0 +1,9 @@
1
+ interface TimestringOptions {
2
+ hoursPerDay?: number;
3
+ daysPerWeek?: number;
4
+ weeksPerMonth?: number;
5
+ monthsPerYear?: number;
6
+ daysPerYear?: number;
7
+ }
8
+ export default function parseTimestring(value: string | number, returnUnit?: string, opts?: TimestringOptions): number;
9
+ export {};
@@ -0,0 +1,83 @@
1
+ const DEFAULT_OPTS = {
2
+ hoursPerDay: 24,
3
+ daysPerWeek: 7,
4
+ weeksPerMonth: 4,
5
+ monthsPerYear: 12,
6
+ daysPerYear: 365.25,
7
+ };
8
+ const UNIT_MAP = {
9
+ ms: ['ms', 'milli', 'millisecond', 'milliseconds'],
10
+ s: ['s', 'sec', 'secs', 'second', 'seconds'],
11
+ m: ['m', 'min', 'mins', 'minute', 'minutes'],
12
+ h: ['h', 'hr', 'hrs', 'hour', 'hours'],
13
+ d: ['d', 'day', 'days'],
14
+ w: ['w', 'week', 'weeks'],
15
+ mth: ['mon', 'mth', 'mths', 'month', 'months'],
16
+ y: ['y', 'yr', 'yrs', 'year', 'years'],
17
+ };
18
+ export default function parseTimestring(value, returnUnit, opts) {
19
+ const options = Object.assign({}, DEFAULT_OPTS, opts || {});
20
+ let strValue;
21
+ if (typeof value === 'number') {
22
+ strValue = parseInt(value.toString()) + 'ms';
23
+ }
24
+ else if (value.match(/^[-+]?[0-9.]+$/g)) {
25
+ strValue = parseInt(value) + 'ms';
26
+ }
27
+ else {
28
+ strValue = value;
29
+ }
30
+ let totalSeconds = 0;
31
+ const unitValues = getUnitValues(options);
32
+ const groups = strValue
33
+ .toLowerCase()
34
+ .replace(/[^.\w+-]+/g, '')
35
+ .match(/[-+]?[0-9.]+[a-z]+/g);
36
+ if (groups === null) {
37
+ throw new Error(`The value [${strValue}] could not be parsed by timestring`);
38
+ }
39
+ groups.forEach((group) => {
40
+ const valMatch = group.match(/[0-9.]+/g);
41
+ const unitMatch = group.match(/[a-z]+/g);
42
+ if (valMatch && unitMatch) {
43
+ const val = parseFloat(valMatch[0]);
44
+ const unit = unitMatch[0];
45
+ totalSeconds += getSeconds(val, unit, unitValues);
46
+ }
47
+ });
48
+ if (returnUnit) {
49
+ return convert(totalSeconds, returnUnit, unitValues);
50
+ }
51
+ return totalSeconds;
52
+ }
53
+ function getUnitValues(opts) {
54
+ const unitValues = {
55
+ ms: 0.001,
56
+ s: 1,
57
+ m: 60,
58
+ h: 3600,
59
+ d: 0,
60
+ w: 0,
61
+ mth: 0,
62
+ y: 0,
63
+ };
64
+ unitValues.d = opts.hoursPerDay * unitValues.h;
65
+ unitValues.w = opts.daysPerWeek * unitValues.d;
66
+ unitValues.mth = (opts.daysPerYear / opts.monthsPerYear) * unitValues.d;
67
+ unitValues.y = opts.daysPerYear * unitValues.d;
68
+ return unitValues;
69
+ }
70
+ function getUnitKey(unit) {
71
+ for (const key of Object.keys(UNIT_MAP)) {
72
+ if (UNIT_MAP[key].indexOf(unit) > -1) {
73
+ return key;
74
+ }
75
+ }
76
+ throw new Error(`The unit [${unit}] is not supported by timestring`);
77
+ }
78
+ function getSeconds(value, unit, unitValues) {
79
+ return value * unitValues[getUnitKey(unit)];
80
+ }
81
+ function convert(value, unit, unitValues) {
82
+ return value / unitValues[getUnitKey(unit)];
83
+ }
package/lib/index.js CHANGED
@@ -38,7 +38,7 @@ const Candle_1 = require("./Candle");
38
38
  Object.defineProperty(exports, "Candle", { enumerable: true, get: function () { return Candle_1.Candle; } });
39
39
  const RawTradeData_1 = require("./RawTradeData");
40
40
  Object.defineProperty(exports, "RawTradeData", { enumerable: true, get: function () { return RawTradeData_1.RawTradeData; } });
41
- let isNode = process || null;
41
+ const isNode = typeof window === 'undefined' && typeof process !== 'undefined';
42
42
  let fetchImpl = null;
43
43
  let fsImpl = null;
44
44
  let ccxt = null;
@@ -0,0 +1,9 @@
1
+ interface TimestringOptions {
2
+ hoursPerDay?: number;
3
+ daysPerWeek?: number;
4
+ weeksPerMonth?: number;
5
+ monthsPerYear?: number;
6
+ daysPerYear?: number;
7
+ }
8
+ export default function parseTimestring(value: string | number, returnUnit?: string, opts?: TimestringOptions): number;
9
+ export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const DEFAULT_OPTS = {
4
+ hoursPerDay: 24,
5
+ daysPerWeek: 7,
6
+ weeksPerMonth: 4,
7
+ monthsPerYear: 12,
8
+ daysPerYear: 365.25,
9
+ };
10
+ const UNIT_MAP = {
11
+ ms: ['ms', 'milli', 'millisecond', 'milliseconds'],
12
+ s: ['s', 'sec', 'secs', 'second', 'seconds'],
13
+ m: ['m', 'min', 'mins', 'minute', 'minutes'],
14
+ h: ['h', 'hr', 'hrs', 'hour', 'hours'],
15
+ d: ['d', 'day', 'days'],
16
+ w: ['w', 'week', 'weeks'],
17
+ mth: ['mon', 'mth', 'mths', 'month', 'months'],
18
+ y: ['y', 'yr', 'yrs', 'year', 'years'],
19
+ };
20
+ function parseTimestring(value, returnUnit, opts) {
21
+ const options = Object.assign({}, DEFAULT_OPTS, opts || {});
22
+ let strValue;
23
+ if (typeof value === 'number') {
24
+ strValue = parseInt(value.toString()) + 'ms';
25
+ }
26
+ else if (value.match(/^[-+]?[0-9.]+$/g)) {
27
+ strValue = parseInt(value) + 'ms';
28
+ }
29
+ else {
30
+ strValue = value;
31
+ }
32
+ let totalSeconds = 0;
33
+ const unitValues = getUnitValues(options);
34
+ const groups = strValue
35
+ .toLowerCase()
36
+ .replace(/[^.\w+-]+/g, '')
37
+ .match(/[-+]?[0-9.]+[a-z]+/g);
38
+ if (groups === null) {
39
+ throw new Error(`The value [${strValue}] could not be parsed by timestring`);
40
+ }
41
+ groups.forEach((group) => {
42
+ const valMatch = group.match(/[0-9.]+/g);
43
+ const unitMatch = group.match(/[a-z]+/g);
44
+ if (valMatch && unitMatch) {
45
+ const val = parseFloat(valMatch[0]);
46
+ const unit = unitMatch[0];
47
+ totalSeconds += getSeconds(val, unit, unitValues);
48
+ }
49
+ });
50
+ if (returnUnit) {
51
+ return convert(totalSeconds, returnUnit, unitValues);
52
+ }
53
+ return totalSeconds;
54
+ }
55
+ exports.default = parseTimestring;
56
+ function getUnitValues(opts) {
57
+ const unitValues = {
58
+ ms: 0.001,
59
+ s: 1,
60
+ m: 60,
61
+ h: 3600,
62
+ d: 0,
63
+ w: 0,
64
+ mth: 0,
65
+ y: 0,
66
+ };
67
+ unitValues.d = opts.hoursPerDay * unitValues.h;
68
+ unitValues.w = opts.daysPerWeek * unitValues.d;
69
+ unitValues.mth = (opts.daysPerYear / opts.monthsPerYear) * unitValues.d;
70
+ unitValues.y = opts.daysPerYear * unitValues.d;
71
+ return unitValues;
72
+ }
73
+ function getUnitKey(unit) {
74
+ for (const key of Object.keys(UNIT_MAP)) {
75
+ if (UNIT_MAP[key].indexOf(unit) > -1) {
76
+ return key;
77
+ }
78
+ }
79
+ throw new Error(`The unit [${unit}] is not supported by timestring`);
80
+ }
81
+ function getSeconds(value, unit, unitValues) {
82
+ return value * unitValues[getUnitKey(unit)];
83
+ }
84
+ function convert(value, unit, unitValues) {
85
+ return value / unitValues[getUnitKey(unit)];
86
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerprotocol/app-loader",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "App Loader for Steer Protocol",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -56,7 +56,6 @@
56
56
  "@semantic-release/npm": "^13.1.3",
57
57
  "@semantic-release/release-notes-generator": "^14.1.0",
58
58
  "@types/jest": "29.5.6",
59
- "@types/timestring": "^6.0.4",
60
59
  "@typescript-eslint/eslint-plugin": "6.8.0",
61
60
  "@typescript-eslint/parser": "6.8.0",
62
61
  "eslint": "8.51.0",
@@ -73,7 +72,6 @@
73
72
  "dependencies": {
74
73
  "ccxt": "^4.1.19",
75
74
  "ethers": "^6.12.1",
76
- "timestring": "^7.0.0",
77
75
  "undici": "^5.26.4"
78
76
  }
79
77
  }