@internetarchive/collection-browser 0.3.1-alpha.3 → 0.3.2-alpha.1

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.
Files changed (30) hide show
  1. package/dist/src/collection-browser.d.ts +6 -0
  2. package/dist/src/collection-browser.js +346 -341
  3. package/dist/src/collection-browser.js.map +1 -1
  4. package/dist/src/collection-facets/facets-template.js +150 -150
  5. package/dist/src/collection-facets/facets-template.js.map +1 -1
  6. package/dist/src/collection-facets/more-facets-content.js +134 -134
  7. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  8. package/dist/src/collection-facets.d.ts +2 -0
  9. package/dist/src/collection-facets.js +158 -147
  10. package/dist/src/collection-facets.js.map +1 -1
  11. package/dist/src/models.js.map +1 -1
  12. package/dist/src/restoration-state-handler.js.map +1 -1
  13. package/dist/src/tiles/list/tile-list.js +204 -204
  14. package/dist/src/tiles/list/tile-list.js.map +1 -1
  15. package/dist/src/utils/format-count.js.map +1 -1
  16. package/dist/test/collection-browser.test.js +26 -26
  17. package/dist/test/collection-browser.test.js.map +1 -1
  18. package/dist/test/collection-facets.test.js +2 -2
  19. package/dist/test/collection-facets.test.js.map +1 -1
  20. package/package.json +1 -1
  21. package/src/collection-browser.ts +1539 -1530
  22. package/src/collection-facets/facets-template.ts +294 -294
  23. package/src/collection-facets/more-facets-content.ts +518 -518
  24. package/src/collection-facets.ts +582 -569
  25. package/src/models.ts +216 -216
  26. package/src/restoration-state-handler.ts +302 -302
  27. package/src/tiles/list/tile-list.ts +509 -509
  28. package/src/utils/format-count.ts +96 -96
  29. package/test/collection-browser.test.ts +490 -490
  30. package/test/collection-facets.test.ts +510 -510
@@ -1,96 +1,96 @@
1
- /*
2
- * Replaces Petabox www/common/Util::number_format()
3
- * For positive numbers only.
4
- */
5
- import { msg, str } from '@lit/localize';
6
-
7
- export type NumberFormat =
8
- | 'short' // 1.2 [K | thousand]
9
- | 'long'; // 1,200 [No label for numbers < 1,000,000]
10
- export type LabelFormat =
11
- | 'short' // [1.2]K
12
- | 'long'; // [1.2] thousand
13
- type Divisor = 1_000_000_000 | 1_000_000 | 1_000 | 1;
14
-
15
- /**
16
- * Return the magnitude of a number.
17
- */
18
- function magnitude(number: number, numberFormat: NumberFormat): Divisor {
19
- let divisor: Divisor = 1;
20
- if (number >= 1_000_000_000) {
21
- divisor = 1_000_000_000;
22
- } else if (number >= 1_000_000) {
23
- divisor = 1_000_000;
24
- } else if (number >= 1_000 && numberFormat === 'short') {
25
- divisor = 1_000;
26
- }
27
- return divisor;
28
- }
29
-
30
- /**
31
- * Round a number given passed magnitude.
32
- * Significant digits of value less than 10 get a decimal.
33
- */
34
- // eslint-disable-next-line default-param-last
35
- function round(number: number = 0, divisor: Divisor): number {
36
- const result = number / divisor;
37
- const roundToOne = result < 10;
38
- let rounded: number = 0;
39
- if (roundToOne) {
40
- rounded = Math.round((result + Number.EPSILON) * 10) / 10;
41
- } else {
42
- rounded = Math.round(result);
43
- }
44
- return rounded;
45
- }
46
-
47
- /**
48
- * Return a label for a number and format.
49
- */
50
- function labelize(
51
- rounded: number,
52
- divisor: Divisor,
53
- format: LabelFormat,
54
- locale: string
55
- ): string {
56
- switch (divisor) {
57
- case 1_000_000_000:
58
- if (format === 'short') {
59
- return msg(str`${rounded}B`);
60
- }
61
- return msg(str`${rounded} billion`);
62
- case 1_000_000:
63
- if (format === 'short') {
64
- return msg(str`${rounded}M`);
65
- }
66
- return msg(str`${rounded} million`);
67
- case 1_000:
68
- if (format === 'short') {
69
- return msg(str`${rounded}K`);
70
- }
71
- return msg(str`${rounded} thousand`);
72
-
73
- default:
74
- return new Intl.NumberFormat(locale).format(rounded);
75
- }
76
- }
77
-
78
- /**
79
- * Format a "count" number into short "icon" or longer text string.
80
- * For positive numbers only.
81
- */
82
- export function formatCount(
83
- count: number | undefined,
84
- numberFormat: NumberFormat = 'long',
85
- labelFormat: LabelFormat = 'short',
86
- locale: string = 'en-US'
87
- ): string {
88
- // Return blank if undefined
89
- const number = count ?? -1;
90
- if (number < 0) {
91
- return '';
92
- }
93
- const divisor = magnitude(number, numberFormat);
94
- const rounded = round(number, divisor);
95
- return labelize(rounded, divisor, labelFormat, locale);
96
- }
1
+ /*
2
+ * Replaces Petabox www/common/Util::number_format()
3
+ * For positive numbers only.
4
+ */
5
+ import { msg, str } from '@lit/localize';
6
+
7
+ export type NumberFormat =
8
+ | 'short' // 1.2 [K | thousand]
9
+ | 'long'; // 1,200 [No label for numbers < 1,000,000]
10
+ export type LabelFormat =
11
+ | 'short' // [1.2]K
12
+ | 'long'; // [1.2] thousand
13
+ type Divisor = 1_000_000_000 | 1_000_000 | 1_000 | 1;
14
+
15
+ /**
16
+ * Return the magnitude of a number.
17
+ */
18
+ function magnitude(number: number, numberFormat: NumberFormat): Divisor {
19
+ let divisor: Divisor = 1;
20
+ if (number >= 1_000_000_000) {
21
+ divisor = 1_000_000_000;
22
+ } else if (number >= 1_000_000) {
23
+ divisor = 1_000_000;
24
+ } else if (number >= 1_000 && numberFormat === 'short') {
25
+ divisor = 1_000;
26
+ }
27
+ return divisor;
28
+ }
29
+
30
+ /**
31
+ * Round a number given passed magnitude.
32
+ * Significant digits of value less than 10 get a decimal.
33
+ */
34
+ // eslint-disable-next-line default-param-last
35
+ function round(number: number = 0, divisor: Divisor): number {
36
+ const result = number / divisor;
37
+ const roundToOne = result < 10;
38
+ let rounded: number = 0;
39
+ if (roundToOne) {
40
+ rounded = Math.round((result + Number.EPSILON) * 10) / 10;
41
+ } else {
42
+ rounded = Math.round(result);
43
+ }
44
+ return rounded;
45
+ }
46
+
47
+ /**
48
+ * Return a label for a number and format.
49
+ */
50
+ function labelize(
51
+ rounded: number,
52
+ divisor: Divisor,
53
+ format: LabelFormat,
54
+ locale: string
55
+ ): string {
56
+ switch (divisor) {
57
+ case 1_000_000_000:
58
+ if (format === 'short') {
59
+ return msg(str`${rounded}B`);
60
+ }
61
+ return msg(str`${rounded} billion`);
62
+ case 1_000_000:
63
+ if (format === 'short') {
64
+ return msg(str`${rounded}M`);
65
+ }
66
+ return msg(str`${rounded} million`);
67
+ case 1_000:
68
+ if (format === 'short') {
69
+ return msg(str`${rounded}K`);
70
+ }
71
+ return msg(str`${rounded} thousand`);
72
+
73
+ default:
74
+ return new Intl.NumberFormat(locale).format(rounded);
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Format a "count" number into short "icon" or longer text string.
80
+ * For positive numbers only.
81
+ */
82
+ export function formatCount(
83
+ count: number | undefined,
84
+ numberFormat: NumberFormat = 'long',
85
+ labelFormat: LabelFormat = 'short',
86
+ locale: string = 'en-US'
87
+ ): string {
88
+ // Return blank if undefined
89
+ const number = count ?? -1;
90
+ if (number < 0) {
91
+ return '';
92
+ }
93
+ const divisor = magnitude(number, numberFormat);
94
+ const rounded = round(number, divisor);
95
+ return labelize(rounded, divisor, labelFormat, locale);
96
+ }