@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.
- package/dist/cjs/utils/duration.js +26 -0
- package/dist/cjs/utils/size.js +25 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/utils/duration.js +26 -0
- package/dist/mjs/utils/size.js +25 -0
- package/dist/types/utils/duration.d.ts +24 -0
- package/dist/types/utils/size.d.ts +23 -0
- package/package.json +2 -2
|
@@ -30,6 +30,32 @@ class Duration {
|
|
|
30
30
|
static fromEndDate(endDate, startDate) {
|
|
31
31
|
return new Duration((endDate.getTime() - (startDate ?? new Date()).getTime()) / 1000);
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Parses a duration string and returns a `Duration` instance.
|
|
35
|
+
*
|
|
36
|
+
* Case insensitive. E.g. both `"28h"` and `"1D"` are valid.
|
|
37
|
+
*
|
|
38
|
+
* Whitespaces are ignored. E.g. both `"5 d"` and `"2weeks"` are valid.
|
|
39
|
+
*
|
|
40
|
+
* Decimal numbers are supported. E.g. `"1.5h"` is valid.
|
|
41
|
+
*
|
|
42
|
+
* Supported units:
|
|
43
|
+
*
|
|
44
|
+
* - ms, milli, millis, millisecond, milliseconds
|
|
45
|
+
* - s, sec, second, seconds
|
|
46
|
+
* - m, min, minute, minutes
|
|
47
|
+
* - h, hour, hours
|
|
48
|
+
* - d, day, days
|
|
49
|
+
* - w, week, weeks
|
|
50
|
+
* - month, months
|
|
51
|
+
* - y, year, years
|
|
52
|
+
*
|
|
53
|
+
* @param duration - A string representing a duration
|
|
54
|
+
* @returns a `Duration` instance
|
|
55
|
+
*/
|
|
56
|
+
static parseFromString(duration) {
|
|
57
|
+
return Duration.fromSeconds(cafe_utility_1.Dates.make(duration) / 1000);
|
|
58
|
+
}
|
|
33
59
|
toSeconds() {
|
|
34
60
|
return this.seconds;
|
|
35
61
|
}
|
package/dist/cjs/utils/size.js
CHANGED
|
@@ -28,6 +28,31 @@ class Size {
|
|
|
28
28
|
static fromGigabytes(gigabytes) {
|
|
29
29
|
return new Size(gigabytes * 1000 * 1000 * 1000);
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses a size string and returns a `Size` instance.
|
|
33
|
+
*
|
|
34
|
+
* Case insensitive. E.g. both `"28MB"` and `"1gb"` are valid.
|
|
35
|
+
*
|
|
36
|
+
* Whitespaces are ignored. E.g. both `"512 kb"` and `"2megabytes"` are valid.
|
|
37
|
+
*
|
|
38
|
+
* Decimal numbers are supported. E.g. `"1.5gb"` is valid.
|
|
39
|
+
*
|
|
40
|
+
* Uses 1000 as the base for conversions. E.g. 1kb = 1000 bytes.
|
|
41
|
+
* This is consistent with the effective stamp utilization table.
|
|
42
|
+
*
|
|
43
|
+
* Supported units:
|
|
44
|
+
* - b, byte, bytes
|
|
45
|
+
* - kb, kilobyte, kilobytes
|
|
46
|
+
* - mb, megabyte, megabytes
|
|
47
|
+
* - gb, gigabyte, gigabytes
|
|
48
|
+
* - tb, terabyte, terabytes
|
|
49
|
+
*
|
|
50
|
+
* @param size - A string representing a size
|
|
51
|
+
* @returns a `Size` instance
|
|
52
|
+
*/
|
|
53
|
+
static parseFromString(size) {
|
|
54
|
+
return Size.fromBytes(cafe_utility_1.Numbers.makeStorage(size, 1000));
|
|
55
|
+
}
|
|
31
56
|
toBytes() {
|
|
32
57
|
return this.bytes;
|
|
33
58
|
}
|