mirror of
https://github.com/Joxit/docker-registry-ui.git
synced 2026-05-23 04:42:47 +00:00
feat(utils): add talgistOrderParser will parse the order string into object
This commit is contained in:
5
src/scripts/error.js
Normal file
5
src/scripts/error.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export class DockerRegistryUIError extends Error {
|
||||
constructor(msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -244,3 +244,21 @@ export const taglistOrderVariants = (taglistOrder) => {
|
||||
throw new DockerRegistryUIError(`The order \`${taglistOrder}\` is not recognized.`);
|
||||
}
|
||||
};
|
||||
|
||||
export function talgistOrderParser(taglistOrder) {
|
||||
const orders = taglistOrderVariants(taglistOrder)
|
||||
.split(';')
|
||||
.filter((e) => e)
|
||||
.map((e) => e.split('-').filter((e) => e))
|
||||
.reduce((acc, e, idx) => {
|
||||
if (e.length > 1) {
|
||||
acc[e[0] + 'Asc'] = e[1] === 'asc';
|
||||
}
|
||||
if (idx === 0) {
|
||||
acc.numFirst = e[0] === 'num';
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return orders;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user