xshell 1.0.165 → 1.0.166

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.0.165",
3
+ "version": "1.0.166",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -92,7 +92,13 @@ export declare class Timer {
92
92
  /** 如果秒表未停止,获取当前秒表读数;
93
93
  如果秒表已停止,获取停止时的秒表读数; */
94
94
  get(): number;
95
- getstr(): string;
95
+ /** 获取时间表示字符串,如 1.2 s
96
+ - parenthesis?: `true` 字符串前后加上括号,如 (1.2 s) */
97
+ getstr(parenthesis?: boolean): string;
96
98
  print(): void;
99
+ /** 重置 started */
100
+ reset(): void;
101
+ get_and_reset(): number;
102
+ getstr_and_reset(parenthesis?: boolean): string;
97
103
  }
98
104
  export declare function lowercase_first_letter(str: string): string;
package/utils.browser.js CHANGED
@@ -270,11 +270,32 @@ export class Timer {
270
270
  get() {
271
271
  return (this.ended || new Date().getTime()) - this.started;
272
272
  }
273
- getstr() {
274
- return `(${delta2str(this.get())})`;
273
+ /** 获取时间表示字符串,如 1.2 s
274
+ - parenthesis?: `true` 字符串前后加上括号,如 (1.2 s) */
275
+ getstr(parenthesis = false) {
276
+ let s = delta2str(this.get());
277
+ if (parenthesis)
278
+ return s.bracket();
279
+ else
280
+ return s;
275
281
  }
276
282
  print() {
277
- console.log(this.getstr());
283
+ console.log(this.getstr(true));
284
+ }
285
+ /** 重置 started */
286
+ reset() {
287
+ this.started = new Date().getTime();
288
+ this.ended = null;
289
+ }
290
+ get_and_reset() {
291
+ const result = this.get();
292
+ this.reset();
293
+ return result;
294
+ }
295
+ getstr_and_reset(parenthesis) {
296
+ const result = this.getstr(parenthesis);
297
+ this.reset();
298
+ return result;
278
299
  }
279
300
  }
280
301
  export function lowercase_first_letter(str) {
package/utils.d.ts CHANGED
@@ -61,9 +61,13 @@ export declare class Timer {
61
61
  如果秒表已停止,获取停止时的秒表读数; */
62
62
  get(): number;
63
63
  /** 获取时间表示字符串,如 1.2 s
64
- - bracket?: `true` 字符串前后加上括号,如 (1.2 s) */
65
- getstr(bracket?: boolean): string;
64
+ - parenthesis?: `true` 字符串前后加上括号,如 (1.2 s) */
65
+ getstr(parenthesis?: boolean): string;
66
66
  print(): void;
67
+ /** 重置 started */
68
+ reset(): void;
69
+ get_and_reset(): number;
70
+ getstr_and_reset(parenthesis?: boolean): string;
67
71
  }
68
72
  export declare function log_line(): void;
69
73
  export declare function delay(milliseconds: number, options?: TimerOptions): Promise<void>;
package/utils.js CHANGED
@@ -189,10 +189,10 @@ export class Timer {
189
189
  return (this.ended || new Date().getTime()) - this.started;
190
190
  }
191
191
  /** 获取时间表示字符串,如 1.2 s
192
- - bracket?: `true` 字符串前后加上括号,如 (1.2 s) */
193
- getstr(bracket = false) {
192
+ - parenthesis?: `true` 字符串前后加上括号,如 (1.2 s) */
193
+ getstr(parenthesis = false) {
194
194
  let s = delta2str(this.get());
195
- if (bracket)
195
+ if (parenthesis)
196
196
  return s.bracket();
197
197
  else
198
198
  return s;
@@ -200,6 +200,21 @@ export class Timer {
200
200
  print() {
201
201
  console.log(this.getstr(true));
202
202
  }
203
+ /** 重置 started */
204
+ reset() {
205
+ this.started = new Date().getTime();
206
+ this.ended = null;
207
+ }
208
+ get_and_reset() {
209
+ const result = this.get();
210
+ this.reset();
211
+ return result;
212
+ }
213
+ getstr_and_reset(parenthesis) {
214
+ const result = this.getstr(parenthesis);
215
+ this.reset();
216
+ return result;
217
+ }
203
218
  }
204
219
  export function log_line() {
205
220
  console.log('---');