web-one 0.0.3 → 0.0.4
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/lib/index.js +67 -6
- package/package.json +1 -1
- package/src/index.ts +80 -3
package/lib/index.js
CHANGED
|
@@ -341,10 +341,6 @@ function formatNumber(v, scale, d, g) {
|
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
exports.formatNumber = formatNumber;
|
|
344
|
-
function getDateFormat(profile) {
|
|
345
|
-
return "M/D/YYYY";
|
|
346
|
-
}
|
|
347
|
-
exports.getDateFormat = getDateFormat;
|
|
348
344
|
function getPage(page) {
|
|
349
345
|
var num = getNumber(page);
|
|
350
346
|
return num === undefined || num < 1 ? 1 : num;
|
|
@@ -372,8 +368,8 @@ function clone(obj) {
|
|
|
372
368
|
if (Array.isArray(obj)) {
|
|
373
369
|
var arr = [];
|
|
374
370
|
for (var _i = 0, obj_1 = obj; _i < obj_1.length; _i++) {
|
|
375
|
-
var
|
|
376
|
-
var c = clone(
|
|
371
|
+
var sub_1 = obj_1[_i];
|
|
372
|
+
var c = clone(sub_1);
|
|
377
373
|
arr.push(c);
|
|
378
374
|
}
|
|
379
375
|
return arr;
|
|
@@ -577,3 +573,68 @@ function formatPhone(phone) {
|
|
|
577
573
|
return formatter.formatPhone(phone);
|
|
578
574
|
}
|
|
579
575
|
exports.formatPhone = formatPhone;
|
|
576
|
+
function rebuildPath(items, lang) {
|
|
577
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
578
|
+
var item = items_1[_i];
|
|
579
|
+
item.path = item.type === "content" ? "/" + lang + item.path : item.path + "?lang=" + lang;
|
|
580
|
+
var children = item.children;
|
|
581
|
+
if (children && children.length > 0) {
|
|
582
|
+
rebuildPath(children, lang);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
exports.rebuildPath = rebuildPath;
|
|
587
|
+
function sub(n1, n2) {
|
|
588
|
+
if (!n1 && !n2) {
|
|
589
|
+
return 0;
|
|
590
|
+
}
|
|
591
|
+
else if (n1 && n2) {
|
|
592
|
+
return n1 - n2;
|
|
593
|
+
}
|
|
594
|
+
else if (n1) {
|
|
595
|
+
return n1;
|
|
596
|
+
}
|
|
597
|
+
else if (n2) {
|
|
598
|
+
return -n2;
|
|
599
|
+
}
|
|
600
|
+
return 0;
|
|
601
|
+
}
|
|
602
|
+
exports.sub = sub;
|
|
603
|
+
function subMenuItem(p1, p2) {
|
|
604
|
+
return sub(p1.sequence, p2.sequence);
|
|
605
|
+
}
|
|
606
|
+
function toMenuItems(m) {
|
|
607
|
+
var ps = getRoot(m);
|
|
608
|
+
for (var _i = 0, ps_1 = ps; _i < ps_1.length; _i++) {
|
|
609
|
+
var p = ps_1[_i];
|
|
610
|
+
getChildren(p, m);
|
|
611
|
+
}
|
|
612
|
+
return ps.sort(subMenuItem);
|
|
613
|
+
}
|
|
614
|
+
exports.toMenuItems = toMenuItems;
|
|
615
|
+
function getRoot(ms) {
|
|
616
|
+
var ps = [];
|
|
617
|
+
for (var _i = 0, ms_1 = ms; _i < ms_1.length; _i++) {
|
|
618
|
+
var m = ms_1[_i];
|
|
619
|
+
if (!m.parent || m.parent.length === 0) {
|
|
620
|
+
delete m.parent;
|
|
621
|
+
ps.push(m);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return ps.sort(subMenuItem);
|
|
625
|
+
}
|
|
626
|
+
function getChildren(m, all) {
|
|
627
|
+
var children = [];
|
|
628
|
+
for (var _i = 0, all_1 = all; _i < all_1.length; _i++) {
|
|
629
|
+
var s = all_1[_i];
|
|
630
|
+
if (s.parent === m.id) {
|
|
631
|
+
delete s.parent;
|
|
632
|
+
children.push(s);
|
|
633
|
+
getChildren(s, all);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
if (children.length > 0) {
|
|
637
|
+
children.sort(subMenuItem);
|
|
638
|
+
m.children = children;
|
|
639
|
+
}
|
|
640
|
+
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -330,9 +330,6 @@ export function formatNumber(v?: number | null, scale?: number, d?: string | nul
|
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
export function getDateFormat(profile?: string): string {
|
|
334
|
-
return "M/D/YYYY"
|
|
335
|
-
}
|
|
336
333
|
export function getPage(page?: string): number {
|
|
337
334
|
const num = getNumber(page)
|
|
338
335
|
return num === undefined || num < 1 ? 1 : num
|
|
@@ -554,3 +551,83 @@ export class formatter {
|
|
|
554
551
|
export function formatPhone(phone?: string | null): string {
|
|
555
552
|
return formatter.formatPhone(phone)
|
|
556
553
|
}
|
|
554
|
+
|
|
555
|
+
export interface MenuItem {
|
|
556
|
+
id: string
|
|
557
|
+
name: string
|
|
558
|
+
path: string
|
|
559
|
+
resource?: string
|
|
560
|
+
icon?: string
|
|
561
|
+
sequence?: number
|
|
562
|
+
prefetch?: boolean
|
|
563
|
+
type?: string
|
|
564
|
+
children?: MenuItem[]
|
|
565
|
+
}
|
|
566
|
+
export interface Category {
|
|
567
|
+
id: string
|
|
568
|
+
name: string
|
|
569
|
+
path: string
|
|
570
|
+
resource?: string
|
|
571
|
+
icon?: string
|
|
572
|
+
sequence?: number
|
|
573
|
+
prefetch?: boolean
|
|
574
|
+
type?: string
|
|
575
|
+
parent?: string
|
|
576
|
+
children?: MenuItem[]
|
|
577
|
+
}
|
|
578
|
+
export function rebuildPath(items: MenuItem[], lang: string) {
|
|
579
|
+
for (const item of items) {
|
|
580
|
+
item.path = item.type === "content" ? `/${lang}${item.path}` : `${item.path}?lang=${lang}`
|
|
581
|
+
const children = item.children
|
|
582
|
+
if (children && children.length > 0) {
|
|
583
|
+
rebuildPath(children, lang)
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export function sub(n1?: number, n2?: number): number {
|
|
589
|
+
if (!n1 && !n2) {
|
|
590
|
+
return 0
|
|
591
|
+
} else if (n1 && n2) {
|
|
592
|
+
return n1 - n2
|
|
593
|
+
} else if (n1) {
|
|
594
|
+
return n1
|
|
595
|
+
} else if (n2) {
|
|
596
|
+
return -n2
|
|
597
|
+
}
|
|
598
|
+
return 0
|
|
599
|
+
}
|
|
600
|
+
function subMenuItem(p1: MenuItem, p2: MenuItem): number {
|
|
601
|
+
return sub(p1.sequence, p2.sequence)
|
|
602
|
+
}
|
|
603
|
+
export function toMenuItems(m: Category[]): MenuItem[] {
|
|
604
|
+
const ps: Category[] = getRoot(m)
|
|
605
|
+
for (const p of ps) {
|
|
606
|
+
getChildren(p, m)
|
|
607
|
+
}
|
|
608
|
+
return ps.sort(subMenuItem)
|
|
609
|
+
}
|
|
610
|
+
function getRoot(ms: Category[]): Category[] {
|
|
611
|
+
const ps: Category[] = []
|
|
612
|
+
for (const m of ms) {
|
|
613
|
+
if (!m.parent || m.parent.length === 0) {
|
|
614
|
+
delete m.parent
|
|
615
|
+
ps.push(m)
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return ps.sort(subMenuItem)
|
|
619
|
+
}
|
|
620
|
+
function getChildren(m: Category, all: Category[]) {
|
|
621
|
+
const children: MenuItem[] = []
|
|
622
|
+
for (const s of all) {
|
|
623
|
+
if (s.parent === m.id) {
|
|
624
|
+
delete s.parent
|
|
625
|
+
children.push(s)
|
|
626
|
+
getChildren(s, all)
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (children.length > 0) {
|
|
630
|
+
children.sort(subMenuItem)
|
|
631
|
+
m.children = children
|
|
632
|
+
}
|
|
633
|
+
}
|