@sit-onyx/flags 1.0.0-beta.0 → 1.0.0-beta.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.
- package/dist/index.js +22 -0
- package/package.json +1 -1
- package/src/assets/CK.svg +1 -1
- package/src/index.ts +31 -0
- package/src/types.ts +17 -0
package/dist/index.js
CHANGED
|
@@ -3,3 +3,25 @@ export {
|
|
|
3
3
|
* Metadata for all available onyx flags.
|
|
4
4
|
*/
|
|
5
5
|
default as FLAG_METADATA, } from "./metadata.json";
|
|
6
|
+
/**
|
|
7
|
+
* Groups all available flag metadata by continent.
|
|
8
|
+
* Continents and flags will be sorted alphabetically.
|
|
9
|
+
*/
|
|
10
|
+
export const groupFlagsByContinent = (flagMetadata) => {
|
|
11
|
+
const continents = Object.entries(flagMetadata).reduce((continents, [code, metadata]) => {
|
|
12
|
+
const flags = continents[metadata.continent] ?? [];
|
|
13
|
+
flags.push({ code, metadata });
|
|
14
|
+
continents[metadata.continent] = flags;
|
|
15
|
+
return continents;
|
|
16
|
+
}, {});
|
|
17
|
+
const sortedContinents = {};
|
|
18
|
+
Object.keys(continents)
|
|
19
|
+
.sort()
|
|
20
|
+
.forEach((continent) => {
|
|
21
|
+
const sortedMetadata = continents[continent].slice().sort((a, b) => {
|
|
22
|
+
return a.code.localeCompare(b.code);
|
|
23
|
+
});
|
|
24
|
+
sortedContinents[continent] = sortedMetadata;
|
|
25
|
+
});
|
|
26
|
+
return sortedContinents;
|
|
27
|
+
};
|
package/package.json
CHANGED
package/src/assets/CK.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><path fill="#6DA544" d="M12 24c6.627 0 12-5.373 12-12S18.627 0 12 0 0 5.373 0 12s5.373 12 12 12"/><path fill="#FFDA44" d="m18.421 17.217.33.689.743-.172-.333.687.598.474-.744.168.002.763-.596-.477-.595.477.002-.763-.745-.168.598-.474-.333-.687.744.172zm-3.063-7.304.329.689.744-.172-.333.687.598.474-.745.168.002.763-.595-.478-.596.478.002-.764-.744-.167.598-.474-.333-.687.743.172zm3.063-4.173.33.688.743-.172-.333.687.598.474-.745.168.002.763-.595-.478-.595.478.002-.763-.745-.168.598-.474-.333-.687.744.172zm2.676 3.13.
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><path fill="#6DA544" d="M12 24c6.627 0 12-5.373 12-12S18.627 0 12 0 0 5.373 0 12s5.373 12 12 12"/><path fill="#FFDA44" d="m18.421 17.217.33.689.743-.172-.333.687.598.474-.744.168.002.763-.596-.477-.595.477.002-.763-.745-.168.598-.474-.333-.687.744.172zm-3.063-7.304.329.689.744-.172-.333.687.598.474-.745.168.002.763-.595-.478-.596.478.002-.764-.744-.167.598-.474-.333-.687.743.172zm3.063-4.173.33.688.743-.172-.333.687.598.474-.745.168.002.763-.595-.478-.595.478.002-.763-.745-.168.598-.474-.333-.687.744.172zm2.676 3.13.33.688.743-.172-.333.687.598.474-.745.168.002.763-.595-.477-.596.477.002-.763-.744-.168.598-.474-.333-.687.744.172zm-1.913 3.652.259.797h.838l-.678.493.259.797-.678-.493-.678.493.259-.797-.679-.493h.839z"/><path fill="#FFDA44" d="M13.305 15.391a3.391 3.391 0 1 1 1.613-6.375 4.174 4.174 0 1 0 0 5.967c-.48.26-1.03.408-1.613.408M7.546 4.696a2.086 2.086 0 0 0-3.614 0zm.007.012L5.739 6.522 3.925 4.708a2.087 2.087 0 1 0 3.628 0"/><path fill="#A2001D" d="M5.217 6v1.76a2.1 2.1 0 0 0 1.044 0V6z"/></svg>
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
|
+
import type { FlagContinents, FlagMetadata } from "./types.js";
|
|
2
|
+
|
|
1
3
|
export {
|
|
2
4
|
/**
|
|
3
5
|
* Metadata for all available onyx flags.
|
|
4
6
|
*/
|
|
5
7
|
default as FLAG_METADATA,
|
|
6
8
|
} from "./metadata.json";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Groups all available flag metadata by continent.
|
|
12
|
+
* Continents and flags will be sorted alphabetically.
|
|
13
|
+
*/
|
|
14
|
+
export const groupFlagsByContinent = (flagMetadata: Record<string, FlagMetadata>) => {
|
|
15
|
+
const continents = Object.entries(flagMetadata).reduce<FlagContinents>(
|
|
16
|
+
(continents, [code, metadata]) => {
|
|
17
|
+
const flags = continents[metadata.continent] ?? [];
|
|
18
|
+
flags.push({ code, metadata });
|
|
19
|
+
continents[metadata.continent] = flags;
|
|
20
|
+
return continents;
|
|
21
|
+
},
|
|
22
|
+
{},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const sortedContinents: typeof continents = {};
|
|
26
|
+
|
|
27
|
+
Object.keys(continents)
|
|
28
|
+
.sort()
|
|
29
|
+
.forEach((continent) => {
|
|
30
|
+
const sortedMetadata = continents[continent].slice().sort((a, b) => {
|
|
31
|
+
return a.code.localeCompare(b.code);
|
|
32
|
+
});
|
|
33
|
+
sortedContinents[continent] = sortedMetadata;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return sortedContinents;
|
|
37
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type FlagMetadata = {
|
|
2
|
+
continent: string;
|
|
3
|
+
internationalName: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type GroupedFlagContinent = {
|
|
7
|
+
/**
|
|
8
|
+
* Country code of the flag.
|
|
9
|
+
*/
|
|
10
|
+
code: string;
|
|
11
|
+
/**
|
|
12
|
+
* Additional flag metadata.
|
|
13
|
+
*/
|
|
14
|
+
metadata: FlagMetadata;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type FlagContinents = Record<string, GroupedFlagContinent[]>;
|