web-one 0.0.8 → 0.0.9
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 +16 -4
- package/package.json +1 -1
- package/src/index.ts +26 -10
package/lib/index.js
CHANGED
|
@@ -674,6 +674,22 @@ function rebuildPath(items, lang) {
|
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
676
|
exports.rebuildPath = rebuildPath;
|
|
677
|
+
function localize(items, resource) {
|
|
678
|
+
for (const item of items) {
|
|
679
|
+
if (item.resource) {
|
|
680
|
+
const text = resource[item.resource];
|
|
681
|
+
if (text) {
|
|
682
|
+
item.name = text;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const children = item.children;
|
|
686
|
+
if (children && children.length > 0) {
|
|
687
|
+
localize(children, resource);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return items;
|
|
691
|
+
}
|
|
692
|
+
exports.localize = localize;
|
|
677
693
|
function sub(n1, n2) {
|
|
678
694
|
if (!n1 && !n2) {
|
|
679
695
|
return 0;
|
|
@@ -725,10 +741,6 @@ function getChildren(m, all) {
|
|
|
725
741
|
m.children = children;
|
|
726
742
|
}
|
|
727
743
|
}
|
|
728
|
-
function cloneArray(arr) {
|
|
729
|
-
return arr.map(item => (Object.assign({}, item)));
|
|
730
|
-
}
|
|
731
|
-
exports.cloneArray = cloneArray;
|
|
732
744
|
function getOffset(limit, page, firstLimit) {
|
|
733
745
|
const p = page && page > 0 ? page : 1;
|
|
734
746
|
if (firstLimit && firstLimit > 0) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function getRecordValue(v: string | string[] | undefined): string | undef
|
|
|
15
15
|
}
|
|
16
16
|
return undefined
|
|
17
17
|
}
|
|
18
|
-
export type StringMap = Record<string, string | string[] | undefined>
|
|
18
|
+
// export type StringMap = Record<string, string | string[] | undefined>
|
|
19
19
|
export function removePage(obj: Record<string, string | string[] | undefined>, pageKey?: string): string {
|
|
20
20
|
const arr: string[] = []
|
|
21
21
|
const keys = Object.keys(obj)
|
|
@@ -438,12 +438,12 @@ export function getLimit(limit: string | undefined, defaultLimit: number): numbe
|
|
|
438
438
|
export function getNumber(num?: string, defaultNum?: number): number | undefined {
|
|
439
439
|
return !num || num.length === 0 ? defaultNum : isNaN(num as any) ? undefined : parseInt(num, 10)
|
|
440
440
|
}
|
|
441
|
-
export function clone(obj:
|
|
441
|
+
export function clone<T>(obj: T): T {
|
|
442
442
|
if (!obj) {
|
|
443
443
|
return obj
|
|
444
444
|
}
|
|
445
445
|
if (obj instanceof Date) {
|
|
446
|
-
return new Date(obj.getTime())
|
|
446
|
+
return new Date(obj.getTime()) as any
|
|
447
447
|
}
|
|
448
448
|
if (typeof obj !== "object") {
|
|
449
449
|
return obj
|
|
@@ -454,12 +454,12 @@ export function clone(obj: any): any {
|
|
|
454
454
|
const c = clone(sub)
|
|
455
455
|
arr.push(c)
|
|
456
456
|
}
|
|
457
|
-
return arr
|
|
457
|
+
return arr as any
|
|
458
458
|
}
|
|
459
459
|
const x: any = {}
|
|
460
460
|
const keys = Object.keys(obj)
|
|
461
461
|
for (const k of keys) {
|
|
462
|
-
const v = obj[k]
|
|
462
|
+
const v = (obj as any)[k]
|
|
463
463
|
if (v instanceof Date) {
|
|
464
464
|
x[k] = new Date(v.getTime())
|
|
465
465
|
} else {
|
|
@@ -650,7 +650,7 @@ export function formatPhone(phone?: string | null): string {
|
|
|
650
650
|
}
|
|
651
651
|
|
|
652
652
|
export interface MenuItem {
|
|
653
|
-
id
|
|
653
|
+
id?: string
|
|
654
654
|
name: string
|
|
655
655
|
path: string
|
|
656
656
|
resource?: string
|
|
@@ -681,6 +681,26 @@ export function rebuildPath(items: MenuItem[], lang: string) {
|
|
|
681
681
|
}
|
|
682
682
|
}
|
|
683
683
|
}
|
|
684
|
+
interface StringMap2 {
|
|
685
|
+
[key: string]: string;
|
|
686
|
+
}
|
|
687
|
+
export function localize(items: MenuItem[], resource: StringMap2): MenuItem[] {
|
|
688
|
+
for (const item of items) {
|
|
689
|
+
if (item.resource) {
|
|
690
|
+
const text = resource[item.resource];
|
|
691
|
+
if (text) {
|
|
692
|
+
item.name = text;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const children = item.children;
|
|
697
|
+
if (children && children.length > 0) {
|
|
698
|
+
localize(children, resource);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
return items;
|
|
703
|
+
}
|
|
684
704
|
|
|
685
705
|
export function sub(n1?: number, n2?: number): number {
|
|
686
706
|
if (!n1 && !n2) {
|
|
@@ -729,10 +749,6 @@ function getChildren(m: Category, all: Category[]) {
|
|
|
729
749
|
}
|
|
730
750
|
}
|
|
731
751
|
|
|
732
|
-
export function cloneArray<T>(arr: T[]): T[] {
|
|
733
|
-
return arr.map(item => ({ ...item }));
|
|
734
|
-
}
|
|
735
|
-
|
|
736
752
|
export function getOffset(limit: number, page?: number, firstLimit?: number): number {
|
|
737
753
|
const p = page && page > 0 ? page : 1
|
|
738
754
|
if (firstLimit && firstLimit > 0) {
|