ag-common 0.0.487 → 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.
@@ -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
- /* eslint-disable no-bitwise */
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 +1,8 @@
1
- export declare function truncate(str: string, n: number, ellip: string): string;
1
+ /** truncate text */
2
+ export declare function truncate(
3
+ /** string to truncate */
4
+ str: string,
5
+ /** max length */
6
+ n: number,
7
+ /** default '...' */
8
+ ellip?: string): string;
@@ -1,7 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.truncate = void 0;
4
- function truncate(str, n, ellip) {
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
  }
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ 'use client';
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
4
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -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, defaultHost, }: {
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: ({ defaultHost, pathname, query, headers, encrypted, }: {
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 = ({ defaultHost, url, }) => {
22
+ const getRenderLanguage = ({ url }) => {
23
23
  var _a, _b, _c, _d;
24
- const prefixReg = new RegExp(`(.*?).(local|${defaultHost.toLowerCase()})`, 'gim');
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, defaultHost, }) => {
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, defaultHost }),
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 = ({ defaultHost, pathname, query, headers, encrypted, }) => {
76
+ const getServerReq = ({ pathname, query, headers, encrypted, }) => {
78
77
  var _a, _b;
79
78
  const href = calculateServerHref({
80
- host: headers.host || defaultHost,
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.487",
2
+ "version": "0.0.488",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",