xshell 1.2.74 → 1.2.76

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.2.74",
3
+ "version": "1.2.76",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -2,3 +2,12 @@ import './prototype.browser.ts';
2
2
  import './platform.browser.ts';
3
3
  export * from './utils.common.ts';
4
4
  export declare function pause(milliseconds?: number): Promise<void>;
5
+ /** 切换所有已选择的 items 中是否包含当前 item */
6
+ export declare function switch_selecteds<TItem>(selecteds: TItem[], item: TItem): TItem[];
7
+ export declare function apply_css(css: string): void;
8
+ export declare function to_option(value: string): {
9
+ label: string;
10
+ value: string;
11
+ };
12
+ export declare function download_url(name: string, url: string): void;
13
+ export declare function download(name: string, data: string | Uint8Array, mime_type?: string): void;
package/utils.browser.js CHANGED
@@ -7,4 +7,36 @@ export async function pause(milliseconds = 3000) {
7
7
  debugger;
8
8
  }
9
9
  globalThis.pause = pause;
10
+ /** 切换所有已选择的 items 中是否包含当前 item */
11
+ export function switch_selecteds(selecteds, item) {
12
+ return selecteds.includes(item) ?
13
+ selecteds.filter(s => s !== item)
14
+ :
15
+ [...selecteds, item];
16
+ }
17
+ export function apply_css(css) {
18
+ let $style = document.createElement('style');
19
+ $style.appendChild(document.createTextNode(css));
20
+ document.head.appendChild($style);
21
+ }
22
+ export function to_option(value) {
23
+ return { label: value, value };
24
+ }
25
+ export function download_url(name, url) {
26
+ // 创建一个隐藏的 <a> 元素
27
+ const a = document.createElement('a');
28
+ a.style.display = 'none';
29
+ a.href = url;
30
+ a.download = name;
31
+ // 将 <a> 元素添加到 DOM 中
32
+ document.body.appendChild(a);
33
+ // 触发下载
34
+ a.click();
35
+ // 下载完成后移除 <a> 元素和 URL 对象
36
+ document.body.removeChild(a);
37
+ URL.revokeObjectURL(url);
38
+ }
39
+ export function download(name, data, mime_type) {
40
+ download_url(name, URL.createObjectURL(new Blob([data], { type: mime_type })));
41
+ }
10
42
  //# sourceMappingURL=utils.browser.js.map
package/utils.common.d.ts CHANGED
@@ -163,3 +163,4 @@ export declare function throttle(duration: number, func: Function, delay_first?:
163
163
  /** 防抖,间隔一段时间不再触发时调用 */
164
164
  export declare function debounce(duration: number, func: Function): (this: any, ...args: any[]) => void;
165
165
  export declare function tomorrow(date?: Date | string | number): Date;
166
+ export declare function to_csv_field(str: string): string;
package/utils.common.js CHANGED
@@ -519,4 +519,7 @@ export function tomorrow(date) {
519
519
  date.setDate(date.getDate() + 1);
520
520
  return date;
521
521
  }
522
+ export function to_csv_field(str) {
523
+ return /[,"\n\r]/.test(str) ? str.replaceAll('"', '""').quote('double') : str;
524
+ }
522
525
  //# sourceMappingURL=utils.common.js.map