@sprucelabs/spruce-heartwood-utils 7.10.5 → 7.11.2
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/build/TimezoneChoiceSorter.d.ts +14 -0
- package/build/TimezoneChoiceSorter.js +55 -0
- package/build/esm/TimezoneChoiceSorter.d.ts +14 -0
- package/build/esm/TimezoneChoiceSorter.js +51 -0
- package/build/esm/index-module.d.ts +1 -0
- package/build/esm/index-module.js +1 -0
- package/build/index-module.d.ts +1 -0
- package/build/index-module.js +3 -1
- package/package.json +5 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Locale } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { SelectChoice } from '@sprucelabs/schema';
|
|
3
|
+
export default class TimezoneChoiceSorter {
|
|
4
|
+
private locale;
|
|
5
|
+
constructor(locale: Locale);
|
|
6
|
+
sort(choices: SelectChoice[]): {
|
|
7
|
+
label: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}[];
|
|
10
|
+
private sortValue;
|
|
11
|
+
private renderLabelForChoice;
|
|
12
|
+
private prefixForOffset;
|
|
13
|
+
private hourOffsetForChoice;
|
|
14
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
class TimezoneChoiceSorter {
|
|
5
|
+
constructor(locale) {
|
|
6
|
+
(0, schema_1.assertOptions)({ locale }, ['locale']);
|
|
7
|
+
this.locale = locale;
|
|
8
|
+
}
|
|
9
|
+
sort(choices) {
|
|
10
|
+
(0, schema_1.assertOptions)({ choices }, ['choices']);
|
|
11
|
+
let results = [];
|
|
12
|
+
if (choices.length > 0) {
|
|
13
|
+
for (const choice of choices) {
|
|
14
|
+
const { label, offset } = this.renderLabelForChoice(choice);
|
|
15
|
+
results.push({
|
|
16
|
+
label,
|
|
17
|
+
offset,
|
|
18
|
+
value: choice.value,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
results.sort((a, b) => {
|
|
23
|
+
const sortA = this.sortValue(a);
|
|
24
|
+
const sortB = this.sortValue(b);
|
|
25
|
+
if (sortA === sortB) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
return sortA > sortB ? 1 : -1;
|
|
29
|
+
});
|
|
30
|
+
const updated = results.map((r) => ({
|
|
31
|
+
label: r.label,
|
|
32
|
+
value: r.value,
|
|
33
|
+
}));
|
|
34
|
+
return updated;
|
|
35
|
+
}
|
|
36
|
+
sortValue(a) {
|
|
37
|
+
const offset = a.offset + 100;
|
|
38
|
+
const searchValue = `${offset * 100}`.padStart(8, '0') + ` - ${a.value}`;
|
|
39
|
+
return searchValue;
|
|
40
|
+
}
|
|
41
|
+
renderLabelForChoice(choice) {
|
|
42
|
+
const offset = this.hourOffsetForChoice(choice);
|
|
43
|
+
const prefix = this.prefixForOffset(offset);
|
|
44
|
+
const label = `(${prefix}${offset}) ` + choice.label;
|
|
45
|
+
return { label, offset };
|
|
46
|
+
}
|
|
47
|
+
prefixForOffset(offset) {
|
|
48
|
+
return offset < 0 ? '' : '+';
|
|
49
|
+
}
|
|
50
|
+
hourOffsetForChoice(choice) {
|
|
51
|
+
return this.locale.zoneNameToOffsetMinutes(choice.value) / 60;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = TimezoneChoiceSorter;
|
|
55
|
+
//# sourceMappingURL=TimezoneChoiceSorter.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Locale } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { SelectChoice } from '@sprucelabs/schema';
|
|
3
|
+
export default class TimezoneChoiceSorter {
|
|
4
|
+
private locale;
|
|
5
|
+
constructor(locale: Locale);
|
|
6
|
+
sort(choices: SelectChoice[]): {
|
|
7
|
+
label: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}[];
|
|
10
|
+
private sortValue;
|
|
11
|
+
private renderLabelForChoice;
|
|
12
|
+
private prefixForOffset;
|
|
13
|
+
private hourOffsetForChoice;
|
|
14
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { assertOptions } from '@sprucelabs/schema';
|
|
2
|
+
export default class TimezoneChoiceSorter {
|
|
3
|
+
constructor(locale) {
|
|
4
|
+
assertOptions({ locale }, ['locale']);
|
|
5
|
+
this.locale = locale;
|
|
6
|
+
}
|
|
7
|
+
sort(choices) {
|
|
8
|
+
assertOptions({ choices }, ['choices']);
|
|
9
|
+
let results = [];
|
|
10
|
+
if (choices.length > 0) {
|
|
11
|
+
for (const choice of choices) {
|
|
12
|
+
const { label, offset } = this.renderLabelForChoice(choice);
|
|
13
|
+
results.push({
|
|
14
|
+
label,
|
|
15
|
+
offset,
|
|
16
|
+
value: choice.value,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
results.sort((a, b) => {
|
|
21
|
+
const sortA = this.sortValue(a);
|
|
22
|
+
const sortB = this.sortValue(b);
|
|
23
|
+
if (sortA === sortB) {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
return sortA > sortB ? 1 : -1;
|
|
27
|
+
});
|
|
28
|
+
const updated = results.map((r) => ({
|
|
29
|
+
label: r.label,
|
|
30
|
+
value: r.value,
|
|
31
|
+
}));
|
|
32
|
+
return updated;
|
|
33
|
+
}
|
|
34
|
+
sortValue(a) {
|
|
35
|
+
const offset = a.offset + 100;
|
|
36
|
+
const searchValue = `${offset * 100}`.padStart(8, '0') + ` - ${a.value}`;
|
|
37
|
+
return searchValue;
|
|
38
|
+
}
|
|
39
|
+
renderLabelForChoice(choice) {
|
|
40
|
+
const offset = this.hourOffsetForChoice(choice);
|
|
41
|
+
const prefix = this.prefixForOffset(offset);
|
|
42
|
+
const label = `(${prefix}${offset}) ` + choice.label;
|
|
43
|
+
return { label, offset };
|
|
44
|
+
}
|
|
45
|
+
prefixForOffset(offset) {
|
|
46
|
+
return offset < 0 ? '' : '+';
|
|
47
|
+
}
|
|
48
|
+
hourOffsetForChoice(choice) {
|
|
49
|
+
return this.locale.zoneNameToOffsetMinutes(choice.value) / 60;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as RemoteViewControllerFactory } from './viewControllers/RemoteViewControllerFactory';
|
|
2
2
|
export { default as CardRegistrar } from './viewControllers/CardRegistrar';
|
|
3
3
|
export { default as remoteVcAssert } from './tests/remoteVcAssert';
|
|
4
|
+
export { default as TimezoneChoiceSorter } from './TimezoneChoiceSorter';
|
|
4
5
|
export * from './types/heartwood-module.types';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as RemoteViewControllerFactory } from './viewControllers/RemoteViewControllerFactory.js';
|
|
2
2
|
export { default as CardRegistrar } from './viewControllers/CardRegistrar.js';
|
|
3
3
|
export { default as remoteVcAssert } from './tests/remoteVcAssert.js';
|
|
4
|
+
export { default as TimezoneChoiceSorter } from './TimezoneChoiceSorter.js';
|
|
4
5
|
export * from './types/heartwood-module.types.js';
|
package/build/index-module.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as RemoteViewControllerFactory } from './viewControllers/RemoteViewControllerFactory';
|
|
2
2
|
export { default as CardRegistrar } from './viewControllers/CardRegistrar';
|
|
3
3
|
export { default as remoteVcAssert } from './tests/remoteVcAssert';
|
|
4
|
+
export { default as TimezoneChoiceSorter } from './TimezoneChoiceSorter';
|
|
4
5
|
export * from './types/heartwood-module.types';
|
package/build/index-module.js
CHANGED
|
@@ -17,12 +17,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.remoteVcAssert = exports.CardRegistrar = exports.RemoteViewControllerFactory = void 0;
|
|
20
|
+
exports.TimezoneChoiceSorter = exports.remoteVcAssert = exports.CardRegistrar = exports.RemoteViewControllerFactory = void 0;
|
|
21
21
|
var RemoteViewControllerFactory_1 = require("./viewControllers/RemoteViewControllerFactory");
|
|
22
22
|
Object.defineProperty(exports, "RemoteViewControllerFactory", { enumerable: true, get: function () { return __importDefault(RemoteViewControllerFactory_1).default; } });
|
|
23
23
|
var CardRegistrar_1 = require("./viewControllers/CardRegistrar");
|
|
24
24
|
Object.defineProperty(exports, "CardRegistrar", { enumerable: true, get: function () { return __importDefault(CardRegistrar_1).default; } });
|
|
25
25
|
var remoteVcAssert_1 = require("./tests/remoteVcAssert");
|
|
26
26
|
Object.defineProperty(exports, "remoteVcAssert", { enumerable: true, get: function () { return __importDefault(remoteVcAssert_1).default; } });
|
|
27
|
+
var TimezoneChoiceSorter_1 = require("./TimezoneChoiceSorter");
|
|
28
|
+
Object.defineProperty(exports, "TimezoneChoiceSorter", { enumerable: true, get: function () { return __importDefault(TimezoneChoiceSorter_1).default; } });
|
|
27
29
|
__exportStar(require("./types/heartwood-module.types"), exports);
|
|
28
30
|
//# sourceMappingURL=index-module.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprucelabs/spruce-heartwood-utils",
|
|
3
3
|
"description": "Heartwood Utilities",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.11.2",
|
|
5
5
|
"skill": {
|
|
6
6
|
"namespace": "heartwood"
|
|
7
7
|
},
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"build/utilities/slug.d.ts",
|
|
39
39
|
"build/esm/utilities/slug.js",
|
|
40
40
|
"build/esm/utilities/slug.d.ts",
|
|
41
|
+
"build/TimezoneChoiceSorter.js",
|
|
42
|
+
"build/TimezoneChoiceSorter.d.ts",
|
|
43
|
+
"build/esm/TimezoneChoiceSorter.js",
|
|
44
|
+
"build/esm/TimezoneChoiceSorter.d.ts",
|
|
41
45
|
"build/types/heartwood-module.types.js",
|
|
42
46
|
"build/types/heartwood-module.types.d.ts",
|
|
43
47
|
"build/esm/types/heartwood-module.types.js",
|