ag-common 0.0.486 → 0.0.488
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/common/helpers/hashCode.d.ts +5 -0
- package/dist/common/helpers/hashCode.js +6 -1
- package/dist/common/helpers/string/truncate.d.ts +8 -1
- package/dist/common/helpers/string/truncate.js +8 -1
- package/dist/ui/components/Toast/base.js +1 -0
- package/dist/ui/helpers/routes.d.ts +2 -17
- package/dist/ui/helpers/routes.js +6 -8
- package/package.json +12 -12
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/** generate int hashcode of string
|
|
2
|
+
* @param seed default 0
|
|
3
|
+
*/
|
|
1
4
|
export declare const hashCodeInt: (str: string, seed?: number) => number;
|
|
5
|
+
/** generate hashcode of string */
|
|
2
6
|
export declare const hashCode: (str: string, seed?: number) => string;
|
|
7
|
+
/** generate a new random string based on the current ms */
|
|
3
8
|
export declare const generateNewPK: () => string;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable no-bitwise */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.generateNewPK = exports.hashCode = exports.hashCodeInt = void 0;
|
|
4
|
-
|
|
5
|
+
/** generate int hashcode of string
|
|
6
|
+
* @param seed default 0
|
|
7
|
+
*/
|
|
5
8
|
const hashCodeInt = (str, seed = 0) => {
|
|
6
9
|
if (!str) {
|
|
7
10
|
return 0;
|
|
@@ -23,7 +26,9 @@ const hashCodeInt = (str, seed = 0) => {
|
|
|
23
26
|
return ret;
|
|
24
27
|
};
|
|
25
28
|
exports.hashCodeInt = hashCodeInt;
|
|
29
|
+
/** generate hashcode of string */
|
|
26
30
|
const hashCode = (str, seed = 0) => (0, exports.hashCodeInt)(str, seed).toString();
|
|
27
31
|
exports.hashCode = hashCode;
|
|
32
|
+
/** generate a new random string based on the current ms */
|
|
28
33
|
const generateNewPK = () => (0, exports.hashCode)(new Date().getTime().toString());
|
|
29
34
|
exports.generateNewPK = generateNewPK;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.truncate = void 0;
|
|
4
|
-
|
|
4
|
+
/** truncate text */
|
|
5
|
+
function truncate(
|
|
6
|
+
/** string to truncate */
|
|
7
|
+
str,
|
|
8
|
+
/** max length */
|
|
9
|
+
n,
|
|
10
|
+
/** default '...' */
|
|
11
|
+
ellip = '...') {
|
|
5
12
|
if (!str) {
|
|
6
13
|
return str;
|
|
7
14
|
}
|
|
@@ -46,7 +46,6 @@ export interface IRequestCommon {
|
|
|
46
46
|
url: LocationSubset;
|
|
47
47
|
lang: TLang;
|
|
48
48
|
userAgent: string;
|
|
49
|
-
defaultHost: string;
|
|
50
49
|
}
|
|
51
50
|
export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialStateCommon {
|
|
52
51
|
request: TRequest;
|
|
@@ -61,7 +60,7 @@ export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialS
|
|
|
61
60
|
* @param param0
|
|
62
61
|
* @returns
|
|
63
62
|
*/
|
|
64
|
-
export declare const getClientOrServerReqHref: ({ url: { href, query, protocol }, forceServer, userAgent, darkMode,
|
|
63
|
+
export declare const getClientOrServerReqHref: ({ url: { href, query, protocol }, forceServer, userAgent, darkMode, }: {
|
|
65
64
|
url: {
|
|
66
65
|
/**
|
|
67
66
|
* parse querystring keyvalues
|
|
@@ -81,19 +80,17 @@ export declare const getClientOrServerReqHref: ({ url: { href, query, protocol }
|
|
|
81
80
|
userAgent?: string | undefined;
|
|
82
81
|
/** will use window.matchMedia */
|
|
83
82
|
darkMode?: boolean | undefined;
|
|
84
|
-
defaultHost: string;
|
|
85
83
|
}) => {
|
|
86
84
|
url: LocationSubset;
|
|
87
85
|
userAgent: string;
|
|
88
86
|
darkMode: boolean;
|
|
89
87
|
lang: TLang;
|
|
90
|
-
defaultHost: string;
|
|
91
88
|
};
|
|
92
89
|
/**
|
|
93
90
|
* get server side parsed url
|
|
94
91
|
* @param param0 * @returns
|
|
95
92
|
*/
|
|
96
|
-
export declare const getServerReq: ({
|
|
93
|
+
export declare const getServerReq: ({ pathname, query, headers, encrypted, }: {
|
|
97
94
|
/**
|
|
98
95
|
* eg ctx?.req?.headers || {}
|
|
99
96
|
*/
|
|
@@ -102,8 +99,6 @@ export declare const getServerReq: ({ defaultHost, pathname, query, headers, enc
|
|
|
102
99
|
'user-agent'?: string;
|
|
103
100
|
'x-forwarded-proto'?: 'http' | 'https';
|
|
104
101
|
};
|
|
105
|
-
/** what to use if host is not available on headers */
|
|
106
|
-
defaultHost: string;
|
|
107
102
|
/**
|
|
108
103
|
* eg ctx.asPath || '/'
|
|
109
104
|
*/
|
|
@@ -121,14 +116,4 @@ export declare const getServerReq: ({ defaultHost, pathname, query, headers, enc
|
|
|
121
116
|
userAgent: string;
|
|
122
117
|
darkMode: boolean;
|
|
123
118
|
lang: TLang;
|
|
124
|
-
defaultHost: string;
|
|
125
119
|
};
|
|
126
|
-
export interface INextCtx {
|
|
127
|
-
req?: {
|
|
128
|
-
headers?: {
|
|
129
|
-
host?: string;
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
asPath?: string;
|
|
133
|
-
query: Record<string, string | string[] | undefined>;
|
|
134
|
-
}
|
|
@@ -19,9 +19,9 @@ const calculateServerHref = ({ host, pathname, }) => {
|
|
|
19
19
|
href += host + pathname;
|
|
20
20
|
return decodeURIComponent(href);
|
|
21
21
|
};
|
|
22
|
-
const getRenderLanguage = ({
|
|
22
|
+
const getRenderLanguage = ({ url }) => {
|
|
23
23
|
var _a, _b, _c, _d;
|
|
24
|
-
const prefixReg = new RegExp(`(.*?).(local|${
|
|
24
|
+
const prefixReg = new RegExp(`(.*?).(local|${url.host.toLowerCase()})`, 'gim');
|
|
25
25
|
const host = (_c = (_b = (_a = url.host) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
|
|
26
26
|
const prefix = host.trim().length !== 0 && ((_d = prefixReg.exec(host)) === null || _d === void 0 ? void 0 : _d[1]);
|
|
27
27
|
if (!prefix) {
|
|
@@ -34,7 +34,7 @@ const getRenderLanguage = ({ defaultHost, url, }) => {
|
|
|
34
34
|
* @param param0
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
37
|
-
const getClientOrServerReqHref = ({ url: { href, query, protocol }, forceServer = false, userAgent, darkMode,
|
|
37
|
+
const getClientOrServerReqHref = ({ url: { href, query, protocol }, forceServer = false, userAgent, darkMode, }) => {
|
|
38
38
|
if (typeof window !== 'undefined') {
|
|
39
39
|
if (!forceServer) {
|
|
40
40
|
href = window.location.href;
|
|
@@ -65,8 +65,7 @@ const getClientOrServerReqHref = ({ url: { href, query, protocol }, forceServer
|
|
|
65
65
|
url,
|
|
66
66
|
userAgent: userAgent !== null && userAgent !== void 0 ? userAgent : '?',
|
|
67
67
|
darkMode: darkMode !== null && darkMode !== void 0 ? darkMode : false,
|
|
68
|
-
lang: getRenderLanguage({ url
|
|
69
|
-
defaultHost,
|
|
68
|
+
lang: getRenderLanguage({ url }),
|
|
70
69
|
};
|
|
71
70
|
};
|
|
72
71
|
exports.getClientOrServerReqHref = getClientOrServerReqHref;
|
|
@@ -74,10 +73,10 @@ exports.getClientOrServerReqHref = getClientOrServerReqHref;
|
|
|
74
73
|
* get server side parsed url
|
|
75
74
|
* @param param0 * @returns
|
|
76
75
|
*/
|
|
77
|
-
const getServerReq = ({
|
|
76
|
+
const getServerReq = ({ pathname, query, headers, encrypted, }) => {
|
|
78
77
|
var _a, _b;
|
|
79
78
|
const href = calculateServerHref({
|
|
80
|
-
host: headers.host ||
|
|
79
|
+
host: headers.host || '?',
|
|
81
80
|
pathname,
|
|
82
81
|
});
|
|
83
82
|
let protocol = 'http:';
|
|
@@ -95,7 +94,6 @@ const getServerReq = ({ defaultHost, pathname, query, headers, encrypted, }) =>
|
|
|
95
94
|
},
|
|
96
95
|
forceServer: true,
|
|
97
96
|
userAgent: (_b = headers['user-agent']) === null || _b === void 0 ? void 0 : _b.toLowerCase(),
|
|
98
|
-
defaultHost,
|
|
99
97
|
});
|
|
100
98
|
return ret;
|
|
101
99
|
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.488",
|
|
3
3
|
"name": "ag-common",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
@@ -43,25 +43,25 @@
|
|
|
43
43
|
"@emotion/react": "11.11.1",
|
|
44
44
|
"@emotion/styled": "11.11.0",
|
|
45
45
|
"@smithy/types": "2.2.2",
|
|
46
|
-
"@storybook/addon-actions": "7.
|
|
47
|
-
"@storybook/addon-docs": "7.
|
|
48
|
-
"@storybook/addon-essentials": "7.
|
|
49
|
-
"@storybook/addon-interactions": "7.
|
|
50
|
-
"@storybook/addon-links": "7.
|
|
51
|
-
"@storybook/addons": "7.
|
|
52
|
-
"@storybook/react": "7.
|
|
53
|
-
"@storybook/react-webpack5": "7.
|
|
54
|
-
"@storybook/theming": "7.
|
|
46
|
+
"@storybook/addon-actions": "7.4.0",
|
|
47
|
+
"@storybook/addon-docs": "7.4.0",
|
|
48
|
+
"@storybook/addon-essentials": "7.4.0",
|
|
49
|
+
"@storybook/addon-interactions": "7.4.0",
|
|
50
|
+
"@storybook/addon-links": "7.4.0",
|
|
51
|
+
"@storybook/addons": "7.4.0",
|
|
52
|
+
"@storybook/react": "7.4.0",
|
|
53
|
+
"@storybook/react-webpack5": "7.4.0",
|
|
54
|
+
"@storybook/theming": "7.4.0",
|
|
55
55
|
"@types/jest": "29.5.4",
|
|
56
56
|
"@types/jsonwebtoken": "9.0.2",
|
|
57
57
|
"@types/node": "20.5.7",
|
|
58
58
|
"@types/react": "18.2.21",
|
|
59
59
|
"@types/react-dom": "18.2.7",
|
|
60
60
|
"cross-env": "7.0.3",
|
|
61
|
-
"eslint-config-e7npm": "0.0.
|
|
61
|
+
"eslint-config-e7npm": "0.0.32",
|
|
62
62
|
"jest": "29.6.4",
|
|
63
63
|
"rimraf": "5.0.1",
|
|
64
|
-
"storybook": "7.
|
|
64
|
+
"storybook": "7.4.0",
|
|
65
65
|
"ts-jest": "29.1.1"
|
|
66
66
|
},
|
|
67
67
|
"files": [
|