@bitblit/ratchet-common 4.0.109-alpha → 4.0.111-alpha
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/lang/esm-ratchet.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import url from 'url';
|
|
2
2
|
export class EsmRatchet {
|
|
3
|
-
static fetchDirName() {
|
|
4
|
-
|
|
3
|
+
static fetchDirName(root) {
|
|
4
|
+
if (!root) {
|
|
5
|
+
throw new Error('Need to provide root (should be import.meta.url)');
|
|
6
|
+
}
|
|
7
|
+
const rval = url.fileURLToPath(new URL('.', root));
|
|
5
8
|
return rval;
|
|
6
9
|
}
|
|
7
|
-
static fetchFileName() {
|
|
8
|
-
|
|
10
|
+
static fetchFileName(root) {
|
|
11
|
+
if (!root) {
|
|
12
|
+
throw new Error('Need to provide root (should be import.meta.url)');
|
|
13
|
+
}
|
|
14
|
+
const rval = url.fileURLToPath(root);
|
|
9
15
|
return rval;
|
|
10
16
|
}
|
|
11
17
|
}
|
|
@@ -27,7 +27,7 @@ describe('#geolocationRatchet', function () {
|
|
|
27
27
|
});
|
|
28
28
|
it('should calc point in bounds', function () {
|
|
29
29
|
const input = fs
|
|
30
|
-
.readFileSync(path.join(EsmRatchet.fetchDirName(), '../../../../test-data/sample_geo_locations.csv'))
|
|
30
|
+
.readFileSync(path.join(EsmRatchet.fetchDirName(import.meta.url), '../../../../test-data/sample_geo_locations.csv'))
|
|
31
31
|
.toString();
|
|
32
32
|
const locations = input
|
|
33
33
|
.split('\n')
|
|
@@ -83,7 +83,7 @@ describe('#fitToWindow', function () {
|
|
|
83
83
|
});
|
|
84
84
|
describe('#groupNumbersIntoContiguousRanges', function () {
|
|
85
85
|
it('should group numbers', function () {
|
|
86
|
-
let input = JSON.parse(fs.readFileSync(path.join(EsmRatchet.fetchDirName(), '../../../../test-data/number_set.json')).toString());
|
|
86
|
+
let input = JSON.parse(fs.readFileSync(path.join(EsmRatchet.fetchDirName(import.meta.url), '../../../../test-data/number_set.json')).toString());
|
|
87
87
|
input = input.map((i) => NumberRatchet.safeNumber(i));
|
|
88
88
|
const grouped = NumberRatchet.groupNumbersIntoContiguousRanges(input, 5);
|
|
89
89
|
expect(grouped).toBeTruthy();
|