@ethersphere/bee-js 10.0.1 → 10.1.0

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.
@@ -27,6 +27,32 @@ export class Duration {
27
27
  static fromEndDate(endDate, startDate) {
28
28
  return new Duration((endDate.getTime() - (startDate ?? new Date()).getTime()) / 1000);
29
29
  }
30
+ /**
31
+ * Parses a duration string and returns a `Duration` instance.
32
+ *
33
+ * Case insensitive. E.g. both `"28h"` and `"1D"` are valid.
34
+ *
35
+ * Whitespaces are ignored. E.g. both `"5 d"` and `"2weeks"` are valid.
36
+ *
37
+ * Decimal numbers are supported. E.g. `"1.5h"` is valid.
38
+ *
39
+ * Supported units:
40
+ *
41
+ * - ms, milli, millis, millisecond, milliseconds
42
+ * - s, sec, second, seconds
43
+ * - m, min, minute, minutes
44
+ * - h, hour, hours
45
+ * - d, day, days
46
+ * - w, week, weeks
47
+ * - month, months
48
+ * - y, year, years
49
+ *
50
+ * @param duration - A string representing a duration
51
+ * @returns a `Duration` instance
52
+ */
53
+ static parseFromString(duration) {
54
+ return Duration.fromSeconds(Dates.make(duration) / 1000);
55
+ }
30
56
  toSeconds() {
31
57
  return this.seconds;
32
58
  }
@@ -25,6 +25,31 @@ export class Size {
25
25
  static fromGigabytes(gigabytes) {
26
26
  return new Size(gigabytes * 1000 * 1000 * 1000);
27
27
  }
28
+ /**
29
+ * Parses a size string and returns a `Size` instance.
30
+ *
31
+ * Case insensitive. E.g. both `"28MB"` and `"1gb"` are valid.
32
+ *
33
+ * Whitespaces are ignored. E.g. both `"512 kb"` and `"2megabytes"` are valid.
34
+ *
35
+ * Decimal numbers are supported. E.g. `"1.5gb"` is valid.
36
+ *
37
+ * Uses 1000 as the base for conversions. E.g. 1kb = 1000 bytes.
38
+ * This is consistent with the effective stamp utilization table.
39
+ *
40
+ * Supported units:
41
+ * - b, byte, bytes
42
+ * - kb, kilobyte, kilobytes
43
+ * - mb, megabyte, megabytes
44
+ * - gb, gigabyte, gigabytes
45
+ * - tb, terabyte, terabytes
46
+ *
47
+ * @param size - A string representing a size
48
+ * @returns a `Size` instance
49
+ */
50
+ static parseFromString(size) {
51
+ return Size.fromBytes(Numbers.makeStorage(size, 1000));
52
+ }
28
53
  toBytes() {
29
54
  return this.bytes;
30
55
  }
@@ -9,6 +9,30 @@ export declare class Duration {
9
9
  static fromWeeks(weeks: number): Duration;
10
10
  static fromYears(years: number): Duration;
11
11
  static fromEndDate(endDate: Date, startDate?: Date): Duration;
12
+ /**
13
+ * Parses a duration string and returns a `Duration` instance.
14
+ *
15
+ * Case insensitive. E.g. both `"28h"` and `"1D"` are valid.
16
+ *
17
+ * Whitespaces are ignored. E.g. both `"5 d"` and `"2weeks"` are valid.
18
+ *
19
+ * Decimal numbers are supported. E.g. `"1.5h"` is valid.
20
+ *
21
+ * Supported units:
22
+ *
23
+ * - ms, milli, millis, millisecond, milliseconds
24
+ * - s, sec, second, seconds
25
+ * - m, min, minute, minutes
26
+ * - h, hour, hours
27
+ * - d, day, days
28
+ * - w, week, weeks
29
+ * - month, months
30
+ * - y, year, years
31
+ *
32
+ * @param duration - A string representing a duration
33
+ * @returns a `Duration` instance
34
+ */
35
+ static parseFromString(duration: string): Duration;
12
36
  toSeconds(): number;
13
37
  toHours(): number;
14
38
  toDays(): number;
@@ -12,6 +12,29 @@ export declare class Size {
12
12
  static fromKilobytes(kilobytes: number): Size;
13
13
  static fromMegabytes(megabytes: number): Size;
14
14
  static fromGigabytes(gigabytes: number): Size;
15
+ /**
16
+ * Parses a size string and returns a `Size` instance.
17
+ *
18
+ * Case insensitive. E.g. both `"28MB"` and `"1gb"` are valid.
19
+ *
20
+ * Whitespaces are ignored. E.g. both `"512 kb"` and `"2megabytes"` are valid.
21
+ *
22
+ * Decimal numbers are supported. E.g. `"1.5gb"` is valid.
23
+ *
24
+ * Uses 1000 as the base for conversions. E.g. 1kb = 1000 bytes.
25
+ * This is consistent with the effective stamp utilization table.
26
+ *
27
+ * Supported units:
28
+ * - b, byte, bytes
29
+ * - kb, kilobyte, kilobytes
30
+ * - mb, megabyte, megabytes
31
+ * - gb, gigabyte, gigabytes
32
+ * - tb, terabyte, terabytes
33
+ *
34
+ * @param size - A string representing a size
35
+ * @returns a `Size` instance
36
+ */
37
+ static parseFromString(size: string): Size;
15
38
  toBytes(): number;
16
39
  toGigabytes(): number;
17
40
  toFormattedString(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "10.0.1",
3
+ "version": "10.1.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "axios": "^0.30.0",
65
- "cafe-utility": "^31.0.0",
65
+ "cafe-utility": "^32.2.0",
66
66
  "debug": "^4.4.1",
67
67
  "isomorphic-ws": "^4.0.1",
68
68
  "semver": "^7.3.5",