sculp-js 0.1.1 → 1.0.0

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/es/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -16,11 +16,11 @@ import { isObject } from './type.js';
16
16
  * @param {string} className
17
17
  * @returns {boolean}
18
18
  */
19
- const hasClass = (el, className) => {
19
+ function hasClass(el, className) {
20
20
  if (className.indexOf(' ') !== -1)
21
21
  throw new Error('className should not contain space.');
22
22
  return el.classList.contains(className);
23
- };
23
+ }
24
24
  const eachClassName = (classNames, func) => {
25
25
  const classNameList = classNames.split(/\s+/g);
26
26
  classNameList.forEach(func);
@@ -30,17 +30,17 @@ const eachClassName = (classNames, func) => {
30
30
  * @param {HTMLElement} el
31
31
  * @param {string} classNames
32
32
  */
33
- const addClass = (el, classNames) => {
33
+ function addClass(el, classNames) {
34
34
  eachClassName(classNames, className => el.classList.add(className));
35
- };
35
+ }
36
36
  /**
37
37
  * 给元素移除样式名
38
38
  * @param {HTMLElement} el
39
39
  * @param {string} classNames
40
40
  */
41
- const removeClass = (el, classNames) => {
41
+ function removeClass(el, classNames) {
42
42
  eachClassName(classNames, className => el.classList.remove(className));
43
- };
43
+ }
44
44
  /**
45
45
  * 设置元素样式
46
46
  * @param {HTMLElement} el
@@ -59,12 +59,14 @@ const setStyle = (el, key, val) => {
59
59
  };
60
60
  /**
61
61
  * 获取元素样式
62
- * @param {HTMLElement} el
62
+ * @param {HTMLElement} el 元素
63
63
  * @param {string} key
64
64
  * @returns {string}
65
65
  */
66
- const getStyle = (el, key) => getComputedStyle(el).getPropertyValue(key);
67
- async function smoothScroll(options) {
66
+ function getStyle(el, key) {
67
+ return getComputedStyle(el).getPropertyValue(key);
68
+ }
69
+ function smoothScroll(options) {
68
70
  return new Promise(resolve => {
69
71
  const defaults = {
70
72
  el: document,
@@ -144,7 +146,7 @@ function onDomReady(callback) {
144
146
  * @param {HTMLElement} el
145
147
  * @param {string} property
146
148
  * @param {boolean} reNumber
147
- * @return {string|number}
149
+ * @returns {string|number}
148
150
  */
149
151
  function getComputedCssVal(el, property, reNumber = true) {
150
152
  const originVal = getComputedStyle(el).getPropertyValue(property) ?? '';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -11,15 +11,15 @@ import { urlSetParams } from './url.js';
11
11
  * @param {string} url
12
12
  * @param {LooseParams} params
13
13
  */
14
- const downloadURL = (url, params) => {
14
+ function downloadURL(url, params) {
15
15
  window.open(params ? urlSetParams(url, params) : url);
16
- };
16
+ }
17
17
  /**
18
18
  * 通过 A 链接的方式下载
19
19
  * @param {string} href
20
20
  * @param {string} filename
21
21
  */
22
- const downloadHref = (href, filename) => {
22
+ function downloadHref(href, filename) {
23
23
  const eleLink = document.createElement('a');
24
24
  eleLink.download = filename;
25
25
  eleLink.style.display = 'none';
@@ -27,17 +27,17 @@ const downloadHref = (href, filename) => {
27
27
  document.body.appendChild(eleLink);
28
28
  eleLink.click();
29
29
  setTimeout(() => document.body.removeChild(eleLink));
30
- };
30
+ }
31
31
  /**
32
32
  * 将大文件对象通过 A 链接的方式下载
33
33
  * @param {Blob} blob
34
34
  * @param {string} filename
35
35
  */
36
- const downloadBlob = (blob, filename) => {
36
+ function downloadBlob(blob, filename) {
37
37
  const objURL = URL.createObjectURL(blob);
38
38
  downloadHref(objURL, filename);
39
39
  setTimeout(() => URL.revokeObjectURL(objURL));
40
- };
40
+ }
41
41
  /**
42
42
  * 将指定数据格式通过 A 链接的方式下载
43
43
  * @param {AnyObject | AnyObject[]} data
@@ -45,7 +45,7 @@ const downloadBlob = (blob, filename) => {
45
45
  * @param {string} filename
46
46
  * @param {string[]} [headers]
47
47
  */
48
- const downloadData = (data, fileType, filename, headers) => {
48
+ function downloadData(data, fileType, filename, headers) {
49
49
  filename = filename.replace(`.${fileType}`, '') + `.${fileType}`;
50
50
  if (fileType === 'json') {
51
51
  const blob = new Blob([JSON.stringify(data, null, 4)]);
@@ -72,6 +72,6 @@ const downloadData = (data, fileType, filename, headers) => {
72
72
  const href = 'data:' + MIMETypes[fileType] + ';charset=utf-8,\ufeff' + encodeURIComponent(headerStr + bodyStr);
73
73
  downloadHref(href, filename);
74
74
  }
75
- };
75
+ }
76
76
 
77
77
  export { downloadBlob, downloadData, downloadHref, downloadURL };
package/lib/es/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/file.js CHANGED
@@ -1,15 +1,16 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  /**
8
8
  * 选择本地文件
9
- * @param {function} changeCb 选择文件回调
10
- * @return {*}
9
+ * @param {string} accept 上传的文件类型,用于过滤
10
+ * @param {Function} changeCb 选择文件回调
11
+ * @returns {HTMLInputElement}
11
12
  */
12
- function chooseLocalFile({ accept }, changeCb) {
13
+ function chooseLocalFile(accept, changeCb) {
13
14
  const inputObj = document.createElement('input');
14
15
  inputObj.setAttribute('id', String(Date.now()));
15
16
  inputObj.setAttribute('type', 'file');
package/lib/es/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -7,7 +7,7 @@
7
7
  export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, deepTraversal, getTreeIds } from './array.js';
8
8
  export { copyText } from './clipboard.js';
9
9
  export { cookieDel, cookieGet, cookieSet } from './cookie.js';
10
- export { calculateDate, calculateDateTime, formatDate } from './date.js';
10
+ export { calculateDate, calculateDateTime, dateParse, dateToEnd, dateToStart, formatDate, isValidDate } from './date.js';
11
11
  export { addClass, getComputedCssVal, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll } from './dom.js';
12
12
  export { downloadBlob, downloadData, downloadHref, downloadURL } from './download.js';
13
13
  export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick } from './object.js';
package/lib/es/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -19,7 +19,7 @@ const remainder = (x, y) => (supportBigInt ? x % y : jsbi().remainder(x, y));
19
19
  * @param {string} [hexPool] 进制池,默认 62 进制
20
20
  * @returns {string}
21
21
  */
22
- const numberToHex = (decimal, hexPool = HEX_POOL) => {
22
+ function numberToHex(decimal, hexPool = HEX_POOL) {
23
23
  if (hexPool.length < 2)
24
24
  throw new Error('进制池长度不能少于 2');
25
25
  if (!supportBigInt) {
@@ -41,7 +41,7 @@ const numberToHex = (decimal, hexPool = HEX_POOL) => {
41
41
  };
42
42
  execute();
43
43
  return ret.join('');
44
- };
44
+ }
45
45
  /**
46
46
  * 缩写
47
47
  * @param {number | string} num
@@ -68,7 +68,7 @@ const numberAbbr = (num, units, ratio = 1000, exponent) => {
68
68
  * 将数字格式化成千位分隔符显示的字符串
69
69
  * @param {number} val 数字
70
70
  * @param {'int' | 'float'} type 展示分段显示的类型 int:整型 | float:浮点型
71
- * @return {string}
71
+ * @returns {string}
72
72
  */
73
73
  function formatNumber(val, type = 'int') {
74
74
  return type === 'int' ? parseInt(String(val)).toLocaleString() : Number(val).toLocaleString('en-US');
package/lib/es/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -27,20 +27,22 @@ const isPlainObject = (obj) => {
27
27
  * @param {string} key
28
28
  * @returns {boolean}
29
29
  */
30
- const objectHas = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
30
+ function objectHas(obj, key) {
31
+ return Object.prototype.hasOwnProperty.call(obj, key);
32
+ }
31
33
  /**
32
34
  * 遍历对象,返回 false 中断遍历
33
35
  * @param {O} obj
34
36
  * @param {(val: O[keyof O], key: keyof O) => (boolean | void)} iterator
35
37
  */
36
- const objectEach = (obj, iterator) => {
38
+ function objectEach(obj, iterator) {
37
39
  for (const key in obj) {
38
40
  if (!objectHas(obj, key))
39
41
  continue;
40
42
  if (iterator(obj[key], key) === false)
41
43
  break;
42
44
  }
43
- };
45
+ }
44
46
  /**
45
47
  * 异步遍历对象,返回 false 中断遍历
46
48
  * @param {O} obj
@@ -146,7 +148,7 @@ const merge = (map, source, target) => {
146
148
  * @param {ObjectAssignItem | undefined} targets
147
149
  * @returns {R}
148
150
  */
149
- const objectAssign = (source, ...targets) => {
151
+ function objectAssign(source, ...targets) {
150
152
  const map = new Map();
151
153
  for (let i = 0; i < targets.length; i++) {
152
154
  const target = targets[i];
@@ -156,7 +158,7 @@ const objectAssign = (source, ...targets) => {
156
158
  }
157
159
  map.clear();
158
160
  return source;
159
- };
161
+ }
160
162
  /**
161
163
  * 对象填充
162
164
  * @param {Partial<R>} source
@@ -164,7 +166,7 @@ const objectAssign = (source, ...targets) => {
164
166
  * @param {(s: Partial<R>, t: Partial<R>, key: keyof R) => boolean} fillable
165
167
  * @returns {R}
166
168
  */
167
- const objectFill = (source, target, fillable) => {
169
+ function objectFill(source, target, fillable) {
168
170
  const _fillable = fillable || ((source, target, key) => source[key] === undefined);
169
171
  objectEach(target, (val, key) => {
170
172
  if (_fillable(source, target, key)) {
@@ -172,7 +174,7 @@ const objectFill = (source, target, fillable) => {
172
174
  }
173
175
  });
174
176
  return source;
175
- };
177
+ }
176
178
  function objectGet(obj, path, strict = false) {
177
179
  path = path.replace(/\[(\w+)\]/g, '.$1');
178
180
  path = path.replace(/^\./, '');
@@ -205,7 +207,7 @@ function objectGet(obj, path, strict = false) {
205
207
  * 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
206
208
  * @param {AnyObject | AnyArray} obj
207
209
  * @param {WeakMap} map
208
- * @return {AnyObject | AnyArray}
210
+ * @returns {AnyObject | AnyArray}
209
211
  */
210
212
  function cloneDeep(obj, map = new WeakMap()) {
211
213
  if (obj instanceof Date)
package/lib/es/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -12,7 +12,7 @@ import { isUndefined, isArray, isString, isNumber, isBoolean, isDate } from './t
12
12
  * @param {string} queryString
13
13
  * @returns {Params}
14
14
  */
15
- const qsParse = (queryString) => {
15
+ function qsParse(queryString) {
16
16
  const params = new URLSearchParams(queryString);
17
17
  const result = {};
18
18
  for (const [key, val] of params.entries()) {
@@ -26,7 +26,7 @@ const qsParse = (queryString) => {
26
26
  result[key] = params.getAll(key);
27
27
  }
28
28
  return result;
29
- };
29
+ }
30
30
  const defaultReplacer = (val) => {
31
31
  if (isString(val))
32
32
  return val;
@@ -44,7 +44,7 @@ const defaultReplacer = (val) => {
44
44
  * @param {Replacer} replacer
45
45
  * @returns {string}
46
46
  */
47
- const qsStringify = (query, replacer = defaultReplacer) => {
47
+ function qsStringify(query, replacer = defaultReplacer) {
48
48
  const params = new URLSearchParams();
49
49
  objectEach(query, (val, key) => {
50
50
  if (isArray(val)) {
@@ -63,6 +63,6 @@ const qsStringify = (query, replacer = defaultReplacer) => {
63
63
  }
64
64
  });
65
65
  return params.toString();
66
- };
66
+ }
67
67
 
68
68
  export { qsParse, qsStringify };
package/lib/es/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/string.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -12,24 +12,24 @@ import { isString } from './type.js';
12
12
  * @param {boolean} [bigger] 是否大写第一个字母
13
13
  * @returns {string}
14
14
  */
15
- const stringCamelCase = (string, bigger) => {
15
+ function stringCamelCase(string, bigger) {
16
16
  let string2 = string;
17
17
  if (bigger) {
18
18
  string2 = string.replace(/^./, origin => origin.toUpperCase());
19
19
  }
20
20
  const HUMP_RE = /[\s_-](.)/g;
21
21
  return string2.replace(HUMP_RE, (orign, char) => char.toUpperCase());
22
- };
22
+ }
23
23
  /**
24
24
  * 将字符串转换为连字格式
25
25
  * @param {string} string
26
26
  * @param {string} [separator] 分隔符,默认是"-"(短横线)
27
27
  * @returns {string}
28
28
  */
29
- const stringKebabCase = (string, separator = '-') => {
29
+ function stringKebabCase(string, separator = '-') {
30
30
  const string2 = string.replace(/^./, origin => origin.toLowerCase());
31
31
  return string2.replace(/[A-Z]/g, origin => `${separator}${origin.toLowerCase()}`);
32
- };
32
+ }
33
33
  const STRING_ARABIC_NUMERALS = '0123456789';
34
34
  const STRING_LOWERCASE_ALPHA = 'abcdefghijklmnopqrstuvwxyz';
35
35
  const STRING_UPPERCASE_ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
@@ -45,7 +45,7 @@ const placeholderRE = /%[%sdo]/g;
45
45
  * @param args
46
46
  * @returns {string}
47
47
  */
48
- const stringFormat = (string, ...args) => {
48
+ function stringFormat(string, ...args) {
49
49
  let index = 0;
50
50
  const result = string.replace(placeholderRE, (origin) => {
51
51
  const arg = args[index++];
@@ -63,7 +63,7 @@ const stringFormat = (string, ...args) => {
63
63
  }
64
64
  });
65
65
  return [result, ...args.splice(index).map(String)].join(' ');
66
- };
66
+ }
67
67
  const ev = (expression, data) => {
68
68
  try {
69
69
  // eslint-disable-next-line @typescript-eslint/no-implied-eval,@typescript-eslint/no-unsafe-return
@@ -127,7 +127,7 @@ const stringFill = (length, value = ' ') => new Array(length).fill(value).join('
127
127
  * @param {string} str 目标字符串
128
128
  * @param {number} fontSize 字符串字体大小
129
129
  * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
130
- * @return {*}
130
+ * @returns {*}
131
131
  */
132
132
  function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
133
133
  let strWidth = 0;
package/lib/es/type.js CHANGED
@@ -1,9 +1,14 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
+ /**
8
+ * 判断任意值的数据类型
9
+ * @param {unknown} any
10
+ * @returns {string}
11
+ */
7
12
  const typeIs = (any) => Object.prototype.toString.call(any).slice(8, -1);
8
13
  // 基本数据类型判断
9
14
  const isString = (any) => typeof any === 'string';
@@ -17,7 +22,11 @@ const isPrimitive = (any) => any === null || typeof any !== 'object';
17
22
  // 复合数据类型判断
18
23
  const isObject = (any) => typeIs(any) === 'Object';
19
24
  const isArray = (any) => Array.isArray(any);
20
- // eslint-disable-next-line @typescript-eslint/ban-types
25
+ /**
26
+ * 判断是否为函数
27
+ * @param {unknown} any
28
+ * @returns {boolean}
29
+ */
21
30
  const isFunction = (any) => typeof any === 'function';
22
31
  // 对象类型判断
23
32
  const isNaN = (any) => Number.isNaN(any);
package/lib/es/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v0.1.0
2
+ * sculp-js v1.0.0
3
3
  * (c) 2023-2023 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -11,17 +11,18 @@
11
11
  * @desc 网页加水印的工具类
12
12
  */
13
13
  /**
14
- * canvas 实现 watermark
14
+ * canvas 实现 水印, 具备防删除功能
15
15
  * @param {ICanvasWM} canvasWM
16
+ * @example genCanvasWM({ content: 'QQMusicFE' })
16
17
  */
17
- const genCanvasWM = (canvasWM) => {
18
+ function genCanvasWM(canvasWM) {
18
19
  const { container = document.body, width = '300px', height = '200px', textAlign = 'center', textBaseline = 'middle', font = '20px PingFangSC-Medium,PingFang SC',
19
20
  // fontWeight = 500,
20
21
  fillStyle = 'rgba(189, 177, 167, .3)', content = '请勿外传', rotate = 30, zIndex = 2147483647 } = canvasWM;
21
22
  // 仅限主页面添加水印
22
- if (!location.pathname.includes('/home')) {
23
- return;
24
- }
23
+ // if (!location.pathname.includes('/home')) {
24
+ // return;
25
+ // }
25
26
  const args = canvasWM;
26
27
  const canvas = document.createElement('canvas');
27
28
  canvas.setAttribute('width', width);
@@ -82,8 +83,6 @@ const genCanvasWM = (canvasWM) => {
82
83
  });
83
84
  mo.observe(container, { attributes: true, subtree: true, childList: true });
84
85
  }
85
- };
86
- // 调用
87
- // __canvasWM({ content: 'QQMusicFE' })
86
+ }
88
87
 
89
88
  export { genCanvasWM };