@raruto/leaflet-elevation 2.6.1 → 2.7.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/src/index.js CHANGED
@@ -1,42 +1,42 @@
1
- /*
2
- * Copyright (c) 2019, GPL-3.0+ Project, Raruto
3
- *
4
- * This file is free software: you may copy, redistribute and/or modify it
5
- * under the terms of the GNU General Public License as published by the
6
- * Free Software Foundation, either version 2 of the License, or (at your
7
- * option) any later version.
8
- *
9
- * This file is distributed in the hope that it will be useful, but
10
- * WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- * General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see .
16
- *
17
- * This file incorporates work covered by the following copyright and
18
- * permission notice:
19
- *
20
- * Copyright (c) 2013-2016, MIT License, Felix “MrMufflon” Bache
21
- *
22
- * Permission to use, copy, modify, and/or distribute this software
23
- * for any purpose with or without fee is hereby granted, provided
24
- * that the above copyright notice and this permission notice appear
25
- * in all copies.
26
- *
27
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
28
- * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
29
- * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
30
- * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
31
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
32
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
33
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
34
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
35
- */
36
-
37
- import * as _ from './utils';
38
- import { Elevation } from './control';
39
-
40
- Elevation.Utils = _;
41
-
42
- L.control.elevation = (options) => new Elevation(options);
1
+ /*
2
+ * Copyright (c) 2019, GPL-3.0+ Project, Raruto
3
+ *
4
+ * This file is free software: you may copy, redistribute and/or modify it
5
+ * under the terms of the GNU General Public License as published by the
6
+ * Free Software Foundation, either version 2 of the License, or (at your
7
+ * option) any later version.
8
+ *
9
+ * This file is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program. If not, see .
16
+ *
17
+ * This file incorporates work covered by the following copyright and
18
+ * permission notice:
19
+ *
20
+ * Copyright (c) 2013-2016, MIT License, Felix “MrMufflon” Bache
21
+ *
22
+ * Permission to use, copy, modify, and/or distribute this software
23
+ * for any purpose with or without fee is hereby granted, provided
24
+ * that the above copyright notice and this permission notice appear
25
+ * in all copies.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
28
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
29
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
30
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
31
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
32
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
33
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
34
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
35
+ */
36
+
37
+ import * as _ from './utils';
38
+ import { Elevation } from './control';
39
+
40
+ Elevation.Utils = _;
41
+
42
+ L.control.elevation = (options) => new Elevation(options);
package/src/options.js CHANGED
@@ -84,5 +84,5 @@ export var Options = {
84
84
  yAxisMin: undefined,
85
85
 
86
86
  // Prevent CORS issues for relative locations (dynamic import)
87
- srcFolder: ((document.currentScript && document.currentScript.src) || (import.meta && import.meta.url)).split("/").slice(0,-1).join("/") + '/',
87
+ srcFolder: ((document.currentScript && document.currentScript.src) || (import.meta && import.meta.url) || document.baseURI).split("/").slice(0,-1).join("/") + '/',
88
88
  };
package/src/utils.spec.js CHANGED
@@ -1,50 +1,48 @@
1
- /**
2
- * src/utils.js
3
- */
4
-
5
- import { suite } from 'uvu';
6
- import * as assert from 'uvu/assert';
7
- import '../test/setup/jsdom.js'
8
- import { iAvg, iMin, iMax, iSum } from "../src/utils.js";
9
-
10
- const toFixed = (n) => +n.toFixed(2);
11
-
12
- const test = suite('src/utils.js');
13
-
14
- test('iAvg()', () => {
15
- let avg;
16
- avg = iAvg(100, undefined, 1); assert.is(toFixed(avg), 100); // average for [100] is 100
17
- avg = iAvg(100, avg, 2); assert.is(toFixed(avg), 100); // average for [100, 100] is 100
18
- avg = iAvg(200, avg, 3); assert.is(toFixed(avg), 133.33); // average for [100, 100, 200] is 133.33
19
- avg = iAvg(200, avg, 4); assert.is(toFixed(avg), 150); // average for [100, 100, 200, 200] is 150
20
- avg = iAvg(NaN, avg, 5); assert.ok(isNaN(avg)); // average for [100, 100, 200, 200, NaN] is NaN
21
- });
22
-
23
- test('iMin()', () => {
24
- let min;
25
- min = iMin(100, undefined); assert.is(toFixed(min), 100); // min for [100] is 100
26
- min = iMin(NaN, min); assert.is(toFixed(min), 100); // min for [100, NaN] is 100
27
- min = iMin(0, min); assert.is(toFixed(min), 0); // min for [100, NaN, 0] is 100
28
- min = iMin(-200, min); assert.is(toFixed(min), -200); // min for [100, NaN, 0, -200] is -200
29
- min = iMin(200, min); assert.is(toFixed(min), -200); // min for [100, NaN, -100, -200, 200] is -200
30
- });
31
-
32
- test('iMax()', () => {
33
- let max;
34
- max = iMax(100, undefined); assert.is(toFixed(max), 100); // max for [100] is 100
35
- max = iMax(NaN, max); assert.is(toFixed(max), 100); // max for [100, NaN] is 100
36
- max = iMax(0, max); assert.is(toFixed(max), 100); // max for [100, NaN, 0] is 100
37
- max = iMax(-200, max); assert.is(toFixed(max), 100); // max for [100, NaN, 0, -200] is 100
38
- max = iMax(200, max); assert.is(toFixed(max), 200); // max for [100, NaN, -100, -200, 200] is 200
39
- });
40
-
41
- test('iSum()', () => {
42
- let sum;
43
- sum = iSum(10.25, undefined); assert.is(toFixed(sum), 10.25); // sum for [10.25] is 10.25
44
- sum = iSum(0, sum); assert.is(toFixed(sum), 10.25); // sum for [10.25, 0] is 10.25
45
- sum = iSum(-0.25, sum); assert.is(toFixed(sum), 10); // sum for [10.25, 0, -0.25] is 10
46
- sum = iSum(-10, sum); assert.is(toFixed(sum), 0); // sum for [10.25, 0, -0.25, -10] is 0
47
- sum = iSum(NaN, sum); assert.ok(isNaN(sum)); // sum for [10.25, 0, -0.25, -10, NaN] is NaN
48
- });
49
-
50
- test.run();
1
+ /**
2
+ * src/utils.js
3
+ */
4
+
5
+ import { test } from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+
8
+ // Importing utils requires Leaflet namespaces, but these arithmetic tests do not use them.
9
+ globalThis.L = { DomEvent: {}, Util: {}, DomUtil: {} };
10
+ const { iAvg, iMin, iMax, iSum } = await import('./utils.js');
11
+
12
+ const toFixed = (n) => +n.toFixed(2);
13
+
14
+ test('iAvg()', () => {
15
+ let avg;
16
+ avg = iAvg(100, undefined, 1); assert.strictEqual(toFixed(avg), 100); // average for [100] is 100
17
+ avg = iAvg(100, avg, 2); assert.strictEqual(toFixed(avg), 100); // average for [100, 100] is 100
18
+ avg = iAvg(200, avg, 3); assert.strictEqual(toFixed(avg), 133.33); // average for [100, 100, 200] is 133.33
19
+ avg = iAvg(200, avg, 4); assert.strictEqual(toFixed(avg), 150); // average for [100, 100, 200, 200] is 150
20
+ avg = iAvg(NaN, avg, 5); assert.ok(isNaN(avg)); // average for [100, 100, 200, 200, NaN] is NaN
21
+ });
22
+
23
+ test('iMin()', () => {
24
+ let min;
25
+ min = iMin(100, undefined); assert.strictEqual(toFixed(min), 100); // min for [100] is 100
26
+ min = iMin(NaN, min); assert.strictEqual(toFixed(min), 100); // min for [100, NaN] is 100
27
+ min = iMin(0, min); assert.strictEqual(toFixed(min), 0); // min for [100, NaN, 0] is 0
28
+ min = iMin(-200, min); assert.strictEqual(toFixed(min), -200); // min for [100, NaN, 0, -200] is -200
29
+ min = iMin(200, min); assert.strictEqual(toFixed(min), -200); // min for [100, NaN, 0, -200, 200] is -200
30
+ });
31
+
32
+ test('iMax()', () => {
33
+ let max;
34
+ max = iMax(100, undefined); assert.strictEqual(toFixed(max), 100); // max for [100] is 100
35
+ max = iMax(NaN, max); assert.strictEqual(toFixed(max), 100); // max for [100, NaN] is 100
36
+ max = iMax(0, max); assert.strictEqual(toFixed(max), 100); // max for [100, NaN, 0] is 100
37
+ max = iMax(-200, max); assert.strictEqual(toFixed(max), 100); // max for [100, NaN, 0, -200] is 100
38
+ max = iMax(200, max); assert.strictEqual(toFixed(max), 200); // max for [100, NaN, 0, -200, 200] is 200
39
+ });
40
+
41
+ test('iSum()', () => {
42
+ let sum;
43
+ sum = iSum(10.25, undefined); assert.strictEqual(toFixed(sum), 10.25); // sum for [10.25] is 10.25
44
+ sum = iSum(0, sum); assert.strictEqual(toFixed(sum), 10.25); // sum for [10.25, 0] is 10.25
45
+ sum = iSum(-0.25, sum); assert.strictEqual(toFixed(sum), 10); // sum for [10.25, 0, -0.25] is 10
46
+ sum = iSum(-10, sum); assert.strictEqual(toFixed(sum), 0); // sum for [10.25, 0, -0.25, -10] is 0
47
+ sum = iSum(NaN, sum); assert.ok(isNaN(sum)); // sum for [10.25, 0, -0.25, -10, NaN] is NaN
48
+ });