@ajaxjs/util 1.1.1 → 1.1.2

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.
Files changed (80) hide show
  1. package/README.md +55 -6
  2. package/dist/index.esm.js +525 -0
  3. package/dist/index.umd.js +536 -0
  4. package/dist/{util → src/core}/cookies.d.ts +18 -18
  5. package/dist/{util → src/core}/dom.d.ts +17 -17
  6. package/dist/{util → src/core}/utils.d.ts +51 -51
  7. package/dist/{util → src/core}/xhr-config.d.ts +22 -22
  8. package/dist/{util → src/core}/xhr.d.ts +71 -71
  9. package/dist/src/index.d.ts +5 -0
  10. package/package.json +39 -43
  11. package/{dist/util/cookies.js → src/core/cookies.ts} +15 -18
  12. package/{dist/util/dom.js → src/core/dom.ts} +17 -14
  13. package/{dist/util/utils.js → src/core/utils.ts} +82 -77
  14. package/src/core/xhr-config.ts +25 -0
  15. package/{dist/util/xhr.js → src/core/xhr.ts} +128 -94
  16. package/src/index.ts +6 -0
  17. package/LICENSE +0 -201
  18. package/dist/index.d.ts +0 -38
  19. package/dist/index.js +0 -71
  20. package/dist/index.js.map +0 -1
  21. package/dist/main.d.ts +0 -1
  22. package/dist/main.js +0 -16
  23. package/dist/main.js.map +0 -1
  24. package/dist/router/index.d.ts +0 -3
  25. package/dist/router/index.js +0 -44
  26. package/dist/router/index.js.map +0 -1
  27. package/dist/router.d.ts +0 -3
  28. package/dist/router.js +0 -44
  29. package/dist/router.js.map +0 -1
  30. package/dist/shims-vue.d.ts +0 -4
  31. package/dist/style/common-functions.less +0 -294
  32. package/dist/style/reset.less +0 -19
  33. package/dist/util/cookies.js.map +0 -1
  34. package/dist/util/dom.js.map +0 -1
  35. package/dist/util/utils.js.map +0 -1
  36. package/dist/util/xhr-config.js +0 -3
  37. package/dist/util/xhr-config.js.map +0 -1
  38. package/dist/util/xhr.js.map +0 -1
  39. package/dist/widget/AccordionMenu.vue +0 -140
  40. package/dist/widget/AdjustFontSize.vue +0 -65
  41. package/dist/widget/Article.vue +0 -59
  42. package/dist/widget/EmptyContent.d.ts +0 -5
  43. package/dist/widget/EmptyContent.js +0 -7
  44. package/dist/widget/EmptyContent.js.map +0 -1
  45. package/dist/widget/Expander.vue +0 -65
  46. package/dist/widget/FileUploader/FileUploader.d.ts +0 -70
  47. package/dist/widget/FileUploader/FileUploader.js +0 -139
  48. package/dist/widget/FileUploader/FileUploader.js.map +0 -1
  49. package/dist/widget/FileUploader/FileUploader.less +0 -68
  50. package/dist/widget/FileUploader/FileUploader.ts +0 -156
  51. package/dist/widget/FileUploader/FileUploader.vue +0 -43
  52. package/dist/widget/HtmlEditor/HtmlEditor.d.ts +0 -70
  53. package/dist/widget/HtmlEditor/HtmlEditor.js +0 -287
  54. package/dist/widget/HtmlEditor/HtmlEditor.js.map +0 -1
  55. package/dist/widget/HtmlEditor/HtmlEditor.less +0 -345
  56. package/dist/widget/HtmlEditor/HtmlEditor.ts +0 -339
  57. package/dist/widget/HtmlEditor/HtmlEditor.vue +0 -70
  58. package/dist/widget/HtmlEditor/html-editor-HtmlSanitizer.js +0 -103
  59. package/dist/widget/ImageEnlarger.vue +0 -105
  60. package/dist/widget/OpacityBanner.vue +0 -125
  61. package/dist/widget/ProcessLine.vue +0 -133
  62. package/dist/widget/Resize.d.ts +0 -51
  63. package/dist/widget/Resize.js +0 -133
  64. package/dist/widget/Resize.js.map +0 -1
  65. package/dist/widget/Resize.ts +0 -152
  66. package/dist/widget/Resize.vue +0 -104
  67. package/dist/widget/TreeSelector.vue +0 -4
  68. package/dist/widget/calendar/BetweenDate.vue +0 -63
  69. package/dist/widget/calendar/Calendar.d.ts +0 -55
  70. package/dist/widget/calendar/Calendar.js +0 -145
  71. package/dist/widget/calendar/Calendar.js.map +0 -1
  72. package/dist/widget/calendar/Calendar.less +0 -210
  73. package/dist/widget/calendar/Calendar.ts +0 -167
  74. package/dist/widget/calendar/Calendar.vue +0 -52
  75. package/dist/widget/calendar/CalendarInput.vue +0 -71
  76. package/dist/widget/form/validator.d.ts +0 -70
  77. package/dist/widget/form/validator.js +0 -220
  78. package/dist/widget/form/validator.js.map +0 -1
  79. package/dist/widget/form/validator.ts +0 -289
  80. package/dist/widget/play-ground/sku.vue +0 -93
@@ -1,51 +1,51 @@
1
- /**
2
- * 通用工具类
3
- */
4
- /**
5
- * 是否调试模式中
6
- *
7
- * 打包成组件之后不能用
8
- *
9
- * @returns
10
- */
11
- export declare function isDebug(): boolean;
12
- export declare function isDev(): boolean;
13
- /**
14
- * 日期格式化。详见博客文章:http://blog.csdn.net/zhangxin09/archive/2011/01/01/6111294.aspx
15
- * e.g: new Date().format("yyyy-MM-dd hh:mm:ss")
16
- *
17
- * @param {String} format
18
- * @return {String}
19
- */
20
- export declare function dateFormat(this: Date, format: string): string;
21
- /**
22
- * 日期格式化
23
- * @author meizz
24
- * @param date 日期,必须为 Date 类型
25
- * @param fmt 格式模板
26
- * @returns 格式化后的字符串
27
- */
28
- export declare function dateFormat2(date: Date, fmt: string): string;
29
- /**
30
- * 并行和串行任务
31
- *
32
- * @author https://segmentfault.com/a/1190000013265925
33
- * @param arr
34
- * @param finnaly
35
- */
36
- export declare function parallel(arr: [], _finally: Function): void;
37
- /**
38
- * 函数节流
39
- *
40
- * @author https://www.cnblogs.com/moqiutao/p/6875955.html
41
- * @param fn
42
- * @param delay
43
- * @param mustRunDelay
44
- */
45
- export declare function throttle(fn: Function, delay: number, mustRunDelay: number): Function;
46
- /**
47
- * 复制文字到剪切板
48
- *
49
- * @param {*} text
50
- */
51
- export declare function copyToClipboard(text: any): void;
1
+ /**
2
+ * 通用工具类
3
+ */
4
+ /**
5
+ * 是否调试模式中
6
+ *
7
+ * 打包成组件之后不能用
8
+ *
9
+ * @returns
10
+ */
11
+ export declare function isDebug(): boolean;
12
+ export declare function isDev(): boolean;
13
+ /**
14
+ * 日期格式化。详见博客文章:http://blog.csdn.net/zhangxin09/archive/2011/01/01/6111294.aspx
15
+ * e.g: new Date().format("yyyy-MM-dd hh:mm:ss")
16
+ *
17
+ * @param {String} format
18
+ * @return {String}
19
+ */
20
+ export declare function dateFormat(this: Date, format: string): string;
21
+ /**
22
+ * 日期格式化
23
+ * @author meizz
24
+ * @param date 日期,必须为 Date 类型
25
+ * @param fmt 格式模板
26
+ * @returns 格式化后的字符串
27
+ */
28
+ export declare function dateFormat2(date: Date, fmt: string): string;
29
+ /**
30
+ * 并行和串行任务
31
+ *
32
+ * @author https://segmentfault.com/a/1190000013265925
33
+ * @param arr
34
+ * @param finnaly
35
+ */
36
+ export declare function parallel(arr: [], _finally: Function): void;
37
+ /**
38
+ * 函数节流
39
+ *
40
+ * @author https://www.cnblogs.com/moqiutao/p/6875955.html
41
+ * @param fn
42
+ * @param delay
43
+ * @param mustRunDelay
44
+ */
45
+ export declare function throttle(fn: Function, delay: number, mustRunDelay: number): Function;
46
+ /**
47
+ * 复制文字到剪切板
48
+ *
49
+ * @param {string} text
50
+ */
51
+ export declare function copyToClipboard(text: string): void;
@@ -1,22 +1,22 @@
1
- /**
2
- * XHR 请求配置
3
- */
4
- export interface XhrConfig {
5
- /**
6
- * 请求头里面的 Content-Type 字段
7
- */
8
- contentType?: string;
9
- /**
10
- * XHR 响应结果的类型
11
- */
12
- parseContentType?: 'text' | 'xml' | 'json';
13
- /**
14
- * 超时时间,单位是毫秒
15
- * 设为 0 适合不控制超时
16
- */
17
- timeout?: number;
18
- /**
19
- * 是否跨域
20
- */
21
- withCredentials?: boolean;
22
- }
1
+ /**
2
+ * XHR 请求配置
3
+ */
4
+ export interface XhrConfig {
5
+ /**
6
+ * 请求头里面的 Content-Type 字段
7
+ */
8
+ contentType?: string;
9
+ /**
10
+ * XHR 响应结果的类型
11
+ */
12
+ parseContentType?: 'text' | 'xml' | 'json';
13
+ /**
14
+ * 超时时间,单位是毫秒
15
+ * 设为 0 适合不控制超时
16
+ */
17
+ timeout?: number;
18
+ /**
19
+ * 是否跨域
20
+ */
21
+ withCredentials?: boolean;
22
+ }
@@ -1,71 +1,71 @@
1
- import { XhrConfig } from './xhr-config';
2
- /**
3
- * 处理响应的回调函数
4
- */
5
- type XhrCallback = (json: {}, text: string) => void;
6
- /**
7
- * 设置全局请求的 head 参数
8
- *
9
- * @param param
10
- */
11
- export declare function setBaseHeadParams(params: any): void;
12
- /**
13
- *
14
- * @param url
15
- * @param cb
16
- * @param params
17
- * @param cfg
18
- */
19
- export declare function xhr_post_upload(url: string, cb: XhrCallback, params: Document | XMLHttpRequestBodyInit, cfg?: XhrConfig): void;
20
- /**
21
- * XHR GET 请求
22
- *
23
- * @param url 请求地址
24
- * @param cb 回调函数 @example (json: {}, text: string) => void;
25
- * @param params 参数,必填,如无填空字符串 "";参数类型是json;参数值会进行 URL 编码,最后附加到 QueryString 中
26
- * @param cfg 配置,可选的
27
- */
28
- export declare function xhr_get(url: string, cb: XhrCallback, params?: {}, cfg?: XhrConfig): void;
29
- /**
30
- * XHR DELETE 请求
31
- *
32
- * @param url 请求地址
33
- * @param cb 回调函数 @example (json: {}, text: string) => void;
34
- * @param params 参数,必填,如无填空字符串 "";参数类型是json;参数值会进行 URL 编码,最后附加到 QueryString 中
35
- * @param cfg 配置,可选的
36
- */
37
- export declare function xhr_del(url: string, cb: XhrCallback, params?: {}, cfg?: XhrConfig): void;
38
- /**
39
- * XHR POST 请求
40
- *
41
- * @param url 请求地址
42
- * @param cb 回调函数 @example (json: {}, text: string) => void;
43
- * @param params 参数,必填,如无填空字符串 "";参数类型可以是字符串或 json;参数值会进行 URL 编码
44
- * @param cfg 配置,可选的
45
- */
46
- export declare function xhr_post(url: string, cb: XhrCallback, params: string | {}, cfg?: XhrConfig): void;
47
- /**
48
- * XHR PUT 请求
49
- *
50
- * @param url 请求地址
51
- * @param cb 回调函数 @example (json: {}, text: string) => void;
52
- * @param params 参数,必填,如无填空字符串 "";参数类型可以是字符串或 json;参数值会进行 URL 编码
53
- * @param cfg 配置,可选的
54
- */
55
- export declare function xhr_put(url: string, cb: XhrCallback, params: string | {}, cfg?: XhrConfig): void;
56
- /**
57
- * 对象转换为 URL 参数列表,用 & 分隔
58
- *
59
- * @param {Object} param JSON 对象
60
- * @returns URL 参数列表
61
- */
62
- export declare function toParams(param: any): string;
63
- /**
64
- * 获取 QueryString 的某个参数
65
- *
66
- * @param val
67
- * @returns
68
- */
69
- export declare function getQuery(val: string): string;
70
- export declare function getPageList(self: any, listArray: any, callback?: Function): XhrCallback;
71
- export {};
1
+ import { XhrConfig } from './xhr-config';
2
+ /**
3
+ * 处理响应的回调函数
4
+ */
5
+ type XhrCallback = (json: {}, text: string) => void;
6
+ /**
7
+ * 设置全局请求的 head 参数
8
+ *
9
+ * @param param
10
+ */
11
+ export declare function setBaseHeadParams(params: any): void;
12
+ /**
13
+ *
14
+ * @param url
15
+ * @param cb
16
+ * @param params
17
+ * @param cfg
18
+ */
19
+ export declare function xhr_post_upload(url: string, cb: XhrCallback, params: Document | XMLHttpRequestBodyInit, cfg?: XhrConfig): void;
20
+ /**
21
+ * XHR GET 请求
22
+ *
23
+ * @param url 请求地址
24
+ * @param cb 回调函数 @example (json: {}, text: string) => void;
25
+ * @param params 参数,必填,如无填空字符串 "";参数类型是json;参数值会进行 URL 编码,最后附加到 QueryString 中
26
+ * @param cfg 配置,可选的
27
+ */
28
+ export declare function xhr_get(url: string, cb: XhrCallback, params?: {}, cfg?: XhrConfig): void;
29
+ /**
30
+ * XHR DELETE 请求
31
+ *
32
+ * @param url 请求地址
33
+ * @param cb 回调函数 @example (json: {}, text: string) => void;
34
+ * @param params 参数,必填,如无填空字符串 "";参数类型是json;参数值会进行 URL 编码,最后附加到 QueryString 中
35
+ * @param cfg 配置,可选的
36
+ */
37
+ export declare function xhr_del(url: string, cb: XhrCallback, params?: {}, cfg?: XhrConfig): void;
38
+ /**
39
+ * XHR POST 请求
40
+ *
41
+ * @param url 请求地址
42
+ * @param cb 回调函数 @example (json: {}, text: string) => void;
43
+ * @param params 参数,必填,如无填空字符串 "";参数类型可以是字符串或 json;参数值会进行 URL 编码
44
+ * @param cfg 配置,可选的
45
+ */
46
+ export declare function xhr_post(url: string, cb: XhrCallback, params: string | {}, cfg?: XhrConfig): void;
47
+ /**
48
+ * XHR PUT 请求
49
+ *
50
+ * @param url 请求地址
51
+ * @param cb 回调函数 @example (json: {}, text: string) => void;
52
+ * @param params 参数,必填,如无填空字符串 "";参数类型可以是字符串或 json;参数值会进行 URL 编码
53
+ * @param cfg 配置,可选的
54
+ */
55
+ export declare function xhr_put(url: string, cb: XhrCallback, params: string | {}, cfg?: XhrConfig): void;
56
+ /**
57
+ * 对象转换为 URL 参数列表,用 & 分隔
58
+ *
59
+ * @param {Object} param JSON 对象
60
+ * @returns URL 参数列表
61
+ */
62
+ export declare function toParams(param: any): string;
63
+ /**
64
+ * 获取 QueryString 的某个参数
65
+ *
66
+ * @param val
67
+ * @returns
68
+ */
69
+ export declare function getQuery(val: string): string;
70
+ export declare function getPageList(self: any, listArray: any, callback?: Function): XhrCallback;
71
+ export {};
@@ -0,0 +1,5 @@
1
+ import * as Cookies from './core/cookies';
2
+ import * as Dom from './core/dom';
3
+ import * as Utils from './core/utils';
4
+ import * as Xhr from './core/xhr';
5
+ export { Cookies, Dom, Utils, Xhr };
package/package.json CHANGED
@@ -1,43 +1,39 @@
1
- {
2
- "name": "@ajaxjs/util",
3
- "version": "1.1.1",
4
- "description": "Real ajaxjs ui library",
5
- "main": "dist/index.js",
6
- "types": "dist/libs/common.d.ts",
7
- "homepage": "https://framework.ajaxjs.com/",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/lightweight-component/js-utils"
11
- },
12
- "bugs": {
13
- "url": "https://github.com/lightweight-component/js-utils/issues"
14
- },
15
- "scripts": {
16
- "dev": "vue-cli-service serve",
17
- "build": "vue-cli-service build",
18
- "release": "tsc && xcopy src\\widget dist\\widget /s /y /d && copy src\\*.d.ts dist\\ && xcopy src\\style dist\\style /s /y /d && npm publish"
19
- },
20
- "keywords": [
21
- "ajaxjs"
22
- ],
23
- "author": "sp42 <sp42@qq.com>",
24
- "license": "Apache License 2.0",
25
- "private": false,
26
- "files": [
27
- "dist"
28
- ],
29
- "devDependencies": {
30
- "@vue/cli-plugin-babel": "~4.5.0",
31
- "@vue/cli-plugin-router": "~4.5.0",
32
- "@vue/cli-plugin-typescript": "~4.5.0",
33
- "@vue/cli-service": "~4.5.0",
34
- "less": "^3.0.4",
35
- "less-loader": "^5.0.0",
36
- "style-resources-loader": "^1.4.1",
37
- "typescript": "^4.4.3",
38
- "vue": "^2.6.14",
39
- "vue-cli-plugin-style-resources-loader": "~0.1.5",
40
- "vue-router": "^3.2.0",
41
- "vue-template-compiler": "^2.6.11"
42
- }
43
- }
1
+ {
2
+ "name": "@ajaxjs/util",
3
+ "version": "1.1.2",
4
+ "description": "Core JS Utils",
5
+ "scripts": {
6
+ "dev": "rollup -w -c",
7
+ "build": "rollup -c"
8
+ },
9
+ "main": "dist/index.umd.js",
10
+ "module": "dist/index.esm.js",
11
+ "types": "dist/index.d.ts",
12
+ "type": "module",
13
+ "files": [
14
+ "src/",
15
+ "dist/"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/lightweight-component/js"
20
+ },
21
+ "keywords": [
22
+ "ajaxjs",
23
+ "util"
24
+ ],
25
+ "author": "Frank Cheung <frank@ajaxjs.com>",
26
+ "license": "Apache License 2.0",
27
+ "devDependencies": {
28
+ "@eslint/js": "^9.9.1",
29
+ "@rollup/plugin-commonjs": "^26.0.1",
30
+ "@rollup/plugin-node-resolve": "^15.2.3",
31
+ "@rollup/plugin-typescript": "^11.1.6",
32
+ "eslint": "^9.9.1",
33
+ "globals": "^15.9.0",
34
+ "rollup": "^4.21.2",
35
+ "tslib": "^2.7.0",
36
+ "typescript": "^5.5.4",
37
+ "typescript-eslint": "^8.4.0"
38
+ }
39
+ }
@@ -1,46 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.delCookie = exports.setCookie = exports.getCookie = void 0;
4
1
  /**
5
2
  * 获取某个 Cookie
6
- *
7
- * @param name 键名称
3
+ *
4
+ * @param name 键名称
8
5
  * @returns 值
9
6
  */
10
- function getCookie(name) {
11
- let arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
7
+ export function getCookie(name: string): string | null {
8
+ let arr: RegExpMatchArray, reg: RegExp = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
9
+ // @ts-ignore
12
10
  if (arr = document.cookie.match(reg))
13
11
  return unescape(arr[2]);
14
12
  else
15
13
  return null;
16
14
  }
17
- exports.getCookie = getCookie;
15
+
18
16
  /**
19
17
  * 设置某个 Cookie
20
- *
21
- * @param name 键名称
18
+ *
19
+ * @param name 键名称
22
20
  * @param value 值
23
21
  */
24
- function setCookie(name, value) {
25
- let days = 2, exp = new Date();
22
+ export function setCookie(name: string, value: string): void {
23
+ let days: number = 2, exp: Date = new Date();
26
24
  exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
27
25
  // @ts-ignore
28
26
  document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();
29
27
  }
30
- exports.setCookie = setCookie;
28
+
31
29
  /**
32
30
  * 清空 Cookie
33
31
  */
34
- function delCookie() {
32
+ export function delCookie(): void {
35
33
  let keys = document.cookie.match(/[^ =;]+(?==)/g);
34
+
36
35
  if (keys) {
37
- let date = new Date(0).toUTCString();
36
+ let date: string = new Date(0).toUTCString();
38
37
  for (let i = keys.length; i--;) {
39
38
  document.cookie = keys[i] + '=0;path=/;expires=' + date; // 清除当前域名下的,例如:m.ratingdog.cn
40
39
  document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + date; // 清除当前域名下的,例如 .m.ratingdog.cn
41
40
  document.cookie = keys[i] + '=0;path=/;domain=' + location.host + ';expires=' + date; // 清除一级域名下的或指定的,例如 .ratingdog.cn
42
41
  }
43
42
  }
44
- }
45
- exports.delCookie = delCookie;
46
- //# sourceMappingURL=cookies.js.map
43
+ }
@@ -1,44 +1,47 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadScript = exports.up = void 0;
4
1
  /**
5
2
  * 向父级元素递归搜索
6
- *
3
+ *
7
4
  * @param _el 当前所在元素
8
5
  * @param tagName 目标标签名称
9
6
  * @param className 目标元素样式类
10
7
  * @returns 目标元素,找不到为 null
11
8
  */
12
- function up(_el, tagName, className) {
9
+ export function up(_el: Element, tagName: string, className: string): Element | null {
13
10
  if (tagName && className)
14
11
  throw '只能任选一种参数,不能同时传';
15
- let el = _el.parentNode;
12
+
13
+ let el: Element = _el.parentNode as Element;
16
14
  tagName = tagName && tagName.toUpperCase();
15
+
17
16
  while (el) {
18
17
  if (tagName && el.tagName == tagName)
19
18
  return el;
19
+
20
20
  if (className && el.className && ~el.className.indexOf(className))
21
21
  return el;
22
- el = el.parentNode;
22
+
23
+ el = <Element>el.parentNode;
23
24
  }
25
+
24
26
  return null;
25
27
  }
26
- exports.up = up;
28
+
27
29
  /**
28
30
  * 加载脚本
29
- *
31
+ *
30
32
  * @param url 脚本地址
31
33
  * @param id 脚本元素 id,可选的
32
34
  * @param cb 回调函数,可选的
33
35
  */
34
- function loadScript(url, id, cb) {
35
- let script = document.createElement("script");
36
+ export function loadScript(url: string, id?: string, cb?: (ev: Event) => any): void {
37
+ let script: HTMLScriptElement = document.createElement("script");
36
38
  script.src = url;
39
+
37
40
  if (cb)
38
41
  script.onload = cb;
42
+
39
43
  if (id)
40
44
  script.id = id;
45
+
41
46
  document.getElementsByTagName("head")[0].appendChild(script);
42
- }
43
- exports.loadScript = loadScript;
44
- //# sourceMappingURL=dom.js.map
47
+ }