@popclip/types 1.4586.0 → 1.4586.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.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Export an object for use by another file.
3
+ *
4
+ * #### Notes
5
+ *
6
+ * The _define_ function family exports an arbitrary object, which other files can import using {@link require}.
7
+ *
8
+ * It should be called only once in any file; if it is called more than once, only the
9
+ * final call will have any effect.
10
+ *
11
+ * Partially implements AMD spec: https://github.com/amdjs/amdjs-api/wiki/AMD
12
+ *
13
+ * Recommendation: instead of this, use {@link defineExtension} or `module.exports = ...`.
14
+ */
15
+ declare function define(object: object): void;
16
+ declare function define(factory: () => object): void;
17
+ declare function define(dependencies: string[], factory: () => object): void;
18
+ declare function define(id: string, factory: () => object): void;
19
+ declare function define(
20
+ id: string,
21
+ dependencies: string[],
22
+ factory: () => object,
23
+ ): void;
@@ -0,0 +1,32 @@
1
+ /* Declare ambient module + exports for CommonJS-style exporting */
2
+ declare const module: { exports: any };
3
+ declare const exports: any;
4
+
5
+ /**
6
+ * Import an object from another file.
7
+ *
8
+ * #### Notes
9
+ *
10
+ * PopClip's `require()` implementation attempts to import from the following module formats:
11
+ *
12
+ * - AMD modules, which use `define(...)`.
13
+ * - CommonJS modules, which use `module.exports = ...` or `exports.name = ...`
14
+ * - TypeScript-compiled ES modules, which use `exports.default = ...`
15
+ *
16
+ * #### Notes
17
+ *
18
+ * Paths beginning with `./` or `../` are resolved relative to the the location of the current file.
19
+ *
20
+ * Otherwise, the path is resolved relative to the extensions's package root.
21
+ * If there is no file in the extension, PopClip will look in its internal module repository.
22
+ *
23
+ * If no file extension is given, PopCLip will try adding the extensions `.js`, `.ts`, `.json` in that order.
24
+ *
25
+ * TypeScript files are transpiled to JavaScript on the fly.
26
+ *
27
+ * JSON files are parsed and returned as an object.å
28
+ *
29
+ * @param file Path to the file to import.
30
+ * @return The imported object.
31
+ */
32
+ declare function require(file: string): object;
@@ -0,0 +1,20 @@
1
+ /* WebAPI and Node.js Globals
2
+ * The following functions and objects are available in PopClip via polyfills.
3
+ * TODO: Not sure how to improve typings for these?
4
+ */
5
+
6
+ // these are from WebAPI, and are implemented in PopClip with polyfills from `core-js` library
7
+ declare function btoa(string: string): string;
8
+ declare function atob(string: string): string;
9
+ declare function structuredClone<T>(value: T): T;
10
+ declare const URL: any;
11
+ declare const URLSearchParams: any;
12
+
13
+ // XMLHttpRequest is implemented natively in PopClip
14
+ declare const XMLHttpRequest: any;
15
+
16
+ // Blob is is a WebAPI object, implemented in PopClip with 'node-blob` library
17
+ declare const Blob: any;
18
+
19
+ // Buffer is a node.js object, implemented in PopClip with 'buffer' library
20
+ declare const Buffer: any;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Call a function after a specified time interval.
3
+ *
4
+ * #### Notes
5
+ *
6
+ * This is PopClip's own implementation of the standard
7
+ * [setTimeout](http://developer.mozilla.org/en-US/docs/Web/API/SetTimeout) function,
8
+ * as found in browsers.
9
+ * Ordinarily you shouldn't need to use this. It is is mainly included for
10
+ * compatibility with libraries that might need it.
11
+ *
12
+ * @param callback A function to be called after the timer expires.
13
+ * @param timeout Timeout in milliseconds. If this parameter is omitted, a value of 0 is used,
14
+ * @param args Additional arguments to be passed to the callback function.
15
+ * @returns Numeric identifier for the timer which can be passed to {@link clearTimeout} to cancel it.
16
+ */
17
+ declare function setTimeout(
18
+ callback: (...args: any) => void,
19
+ timeout?: number,
20
+ ...args: any
21
+ ): number;
22
+
23
+ /**
24
+ * Cancels a timeout prevouly created with {@link setTimeout}.
25
+ * @param timeoutId Identifier of the timeout to cancel.
26
+ */
27
+ declare function clearTimeout(timeoutId: number): void;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@popclip/types",
3
+ "version": "1.4586.2",
4
+ "devDependencies": {
5
+ "typedoc": "0.25.13",
6
+ "typescript": "5.4.5"
7
+ },
3
8
  "license": "MIT",
4
- "version": "1.4586.0",
5
- "types": "./popclip.d.ts",
6
9
  "scripts": {
7
10
  "check": "tsc --noEmit",
8
11
  "docs": "typedoc"
9
12
  },
10
- "devDependencies": {
11
- "typedoc": "0.25.13",
12
- "typescript": "5.4.5"
13
- }
13
+ "types": "./popclip.d.ts"
14
14
  }
package/popclip.d.ts CHANGED
@@ -5,7 +5,7 @@ This is a TypeScript definitions file for PopClip's JavaScript interface.
5
5
  /**
6
6
  * An object giving strings for the different languages PopClip supports. See {@link LocalizableString}.
7
7
  */
8
- declare interface StringTable {
8
+ interface StringTable {
9
9
  /** English (US) language string. */
10
10
  en: string;
11
11
  /** English (UK) language string. */
@@ -62,14 +62,14 @@ declare interface StringTable {
62
62
  * option.label = { en: "Color", "en-GB": "Colour", fr: "Couleur", "zh-Hans": "颜色" }
63
63
  * ```
64
64
  */
65
- declare type LocalizableString = string | StringTable;
65
+ type LocalizableString = string | StringTable;
66
66
 
67
67
  /**
68
68
  * Represents the state of the four modifier keys. The value is true when the key is held down
69
69
  * at the time the action is invoked.
70
70
  * See {@link PopClip.modifiers}.
71
71
  */
72
- declare interface Modifiers {
72
+ interface Modifiers {
73
73
  /** Shift (⇧) key state. */
74
74
  shift: boolean;
75
75
  /** Control (⌃) key state. */
@@ -88,7 +88,7 @@ declare interface Modifiers {
88
88
  * ["paste", "!urls", "option-goFishing=1"]
89
89
  * ```
90
90
  */
91
- declare type Requirement =
91
+ type Requirement =
92
92
  | "text"
93
93
  | "cut"
94
94
  | "paste"
@@ -101,17 +101,17 @@ declare type Requirement =
101
101
  | `option-${string}=${string}`;
102
102
 
103
103
  /** Negated form of {@link Requirement}. */
104
- declare type NegatedRequirement = `!${Requirement}`;
104
+ type NegatedRequirement = `!${Requirement}`;
105
105
 
106
106
  /**
107
107
  * Strings which can be used to specify the {@link Action.before} action.
108
108
  */
109
- declare type BeforeStep = "cut" | "copy" | "paste" | "paste-plain";
109
+ type BeforeStep = "cut" | "copy" | "paste" | "paste-plain";
110
110
 
111
111
  /**
112
112
  * Strings which can be used to specify the {@link Action.after} action.
113
113
  */
114
- declare type AfterStep =
114
+ type AfterStep =
115
115
  | BeforeStep
116
116
  | "popclip-appear"
117
117
  | "show-status"
@@ -123,7 +123,7 @@ declare type AfterStep =
123
123
  /**
124
124
  * Declares information about an app or website that this extension interacts with.
125
125
  */
126
- declare interface AssociatedApp {
126
+ interface AssociatedApp {
127
127
  /**
128
128
  * Name of the app. For example "Scrivener"
129
129
  */
@@ -152,7 +152,7 @@ declare interface AssociatedApp {
152
152
  * @param context Information about the context surrounding the selection. (Same object as {@link PopClip.context}.)
153
153
  * @returns A single action, an array of actions.
154
154
  */
155
- declare type PopulationFunction<CustomOptions extends Options = Options> = (
155
+ type PopulationFunction<CustomOptions extends Options = Options> = (
156
156
  input: Input,
157
157
  options: CustomOptions,
158
158
  context: Context,
@@ -161,7 +161,7 @@ declare type PopulationFunction<CustomOptions extends Options = Options> = (
161
161
  /**
162
162
  * Object returned by {@link Extension.auth} when there is an authentication flow to kick off
163
163
  */
164
- declare type AuthFlowFunction = (
164
+ type AuthFlowFunction = (
165
165
  url: string,
166
166
  params?: { [key: string]: string | undefined },
167
167
  expect?: string[],
@@ -170,7 +170,7 @@ declare type AuthFlowFunction = (
170
170
  /**
171
171
  * Credentials used in auth function
172
172
  * */
173
- declare interface AuthInfo {
173
+ interface AuthInfo {
174
174
  /** Value of `username` option (will be empty string if none defined) */
175
175
  username: string;
176
176
  /** Value of `password` option (will be empty string if none defined) */
@@ -189,15 +189,12 @@ declare interface AuthInfo {
189
189
  /**
190
190
  * Function signature of the {@link Extension.auth} method.
191
191
  */
192
- declare type AuthFunction = (
193
- info: AuthInfo,
194
- flow: AuthFlowFunction,
195
- ) => Promise<string>;
192
+ type AuthFunction = (info: AuthInfo, flow: AuthFlowFunction) => Promise<string>;
196
193
 
197
194
  /**
198
195
  * Properties that define how an icon is interpreted.
199
196
  */
200
- declare interface IconProperties {
197
+ interface IconProperties {
201
198
  /**
202
199
  * If true, the supplied icon will be displayed with its original color instead of being filled in white/black. Default is false.
203
200
  */
@@ -269,7 +266,7 @@ declare interface IconProperties {
269
266
  /**
270
267
  * Properties common to Action and Extension
271
268
  */
272
- declare interface ActionProperties extends IconProperties {
269
+ interface ActionProperties extends IconProperties {
273
270
  /**
274
271
  * A unique identifying string. An identifier for an action can be any string of your choosing.
275
272
  */
@@ -416,7 +413,7 @@ declare interface ActionProperties extends IconProperties {
416
413
  * @param options Current values of the options for this extension. (Same object as {@link PopClip.options}.)
417
414
  * @param context Information about the context surrounding the selection. (Same object as {@link PopClip.context}.)
418
415
  */
419
- declare type ActionFunction<CustomOptions extends Options = Options> = (
416
+ type ActionFunction<CustomOptions extends Options = Options> = (
420
417
  input: Input,
421
418
  options: CustomOptions & AuthOptions,
422
419
  context: Context,
@@ -426,18 +423,18 @@ declare type ActionFunction<CustomOptions extends Options = Options> = (
426
423
  * **Action** represents the properties of a single action.
427
424
  * If `code` is omitted, the action displays a disabled title/icon only.
428
425
  */
429
- declare interface Action<CustomOptions extends Options = Options>
426
+ interface Action<CustomOptions extends Options = Options>
430
427
  extends ActionProperties {
431
428
  code?: ActionFunction<CustomOptions>;
432
429
  }
433
430
 
434
431
  // included for JSON Schema
435
- declare type Entitlement = "network" | "dynamic";
432
+ type Entitlement = "network" | "dynamic";
436
433
 
437
434
  /**
438
435
  * The Extension object defines the PopClip extension.
439
436
  */
440
- declare interface Extension<CustomOptions extends Options = Options>
437
+ interface Extension<CustomOptions extends Options = Options>
441
438
  extends ActionProperties {
442
439
  /**
443
440
  * The display name of this extension.
@@ -483,10 +480,18 @@ declare interface Extension<CustomOptions extends Options = Options>
483
480
  module?: string;
484
481
  }
485
482
 
483
+ type OptionType =
484
+ | "string"
485
+ | "boolean"
486
+ | "multiple"
487
+ | "password"
488
+ | "heading"
489
+ | "secret";
490
+
486
491
  /**
487
492
  * Defines a single extension option.
488
493
  */
489
- declare interface Option {
494
+ interface OptionBase {
490
495
  /**
491
496
  * An identifying string for this option.
492
497
  */
@@ -501,7 +506,7 @@ declare interface Option {
501
506
  * * `password`: concealed text entry field (not persisted, only passed to auth function),
502
507
  * * `heading`: adds a heading in the user interface, but does not actually define an option
503
508
  */
504
- type: "string" | "boolean" | "multiple" | "password" | "heading" | "secret";
509
+ type: OptionType;
505
510
 
506
511
  /**
507
512
  * A short label for this option.
@@ -513,10 +518,29 @@ declare interface Option {
513
518
  */
514
519
  description?: LocalizableString;
515
520
 
521
+ /*
522
+ * If true, this option will be hidden in the prefs window. Default is false.
523
+ */
524
+ hidden?: boolean;
525
+
526
+ /*
527
+ * If true, this option will be be inset to the right of its label, instead of below it. Default is false.
528
+ */
529
+ inset?: boolean;
530
+ }
531
+
532
+ interface StringOption extends OptionBase {
533
+ type: "string";
516
534
  /**
517
- * The default value of the option. If ommitted, `string` options default to the empty string,
518
- * `boolean` options default to true, and `multiple` options default to the top item in the list.
519
- * A `password` field may not have a default value.
535
+ * The default value of the option. If omitted, `string` options default to the empty string.
536
+ */
537
+ defaultValue?: string;
538
+ }
539
+
540
+ interface MultipleOption extends OptionBase {
541
+ type: "multiple";
542
+ /**
543
+ * The default value of the option. If omitted, `multiple` options default to the top item in the list.
520
544
  */
521
545
  defaultValue?: string | boolean;
522
546
 
@@ -530,27 +554,39 @@ declare interface Option {
530
554
  * If ommitted, the raw value strings are shown instead.
531
555
  */
532
556
  valueLabels?: LocalizableString[];
557
+ }
533
558
 
559
+ interface BooleanOption extends OptionBase {
560
+ type: "boolean";
561
+ /**
562
+ * The default value of the option. If omitted, `boolean` options default to true.
563
+ */
564
+ defaultValue?: boolean;
534
565
  /**
535
566
  * An icon for this option. It is only displayed for boolean options, next to the check box.
536
567
  */
537
568
  icon?: string;
569
+ }
538
570
 
539
- /*
540
- * If true, this option will be hidden in the prefs window. Default is false.
541
- */
542
- hidden?: boolean;
571
+ interface PasswordOption extends OptionBase {
572
+ type: "password" | "secret";
573
+ }
543
574
 
544
- /*
545
- * If true, this option will be be inset to the right of its label, instead of below it. Default is false.
546
- */
547
- inset?: boolean;
575
+ interface HeadingOption extends OptionBase {
576
+ type: "heading";
548
577
  }
549
578
 
579
+ type Option =
580
+ | StringOption
581
+ | MultipleOption
582
+ | BooleanOption
583
+ | PasswordOption
584
+ | HeadingOption;
585
+
550
586
  /**
551
587
  * Represents a generic range, as a location and length
552
588
  */
553
- declare interface Range {
589
+ interface Range {
554
590
  location: number;
555
591
  length: number;
556
592
  }
@@ -558,14 +594,14 @@ declare interface Range {
558
594
  /**
559
595
  * An array of strings with an addiontal `ranges` property defining the source of the data in the orignal string.
560
596
  */
561
- declare interface RangedStrings extends Array<string> {
597
+ interface RangedStrings extends Array<string> {
562
598
  ranges: Range[];
563
599
  }
564
600
 
565
601
  /**
566
602
  * Input defines properties to access the input text contents.
567
603
  */
568
- declare interface Input {
604
+ interface Input {
569
605
  /**
570
606
  * The plain text selected by the user. If there is no selected text, this will be the empty string.
571
607
  */
@@ -654,7 +690,7 @@ declare interface Input {
654
690
  /**
655
691
  * Properties relating the context surrounding the selected text.
656
692
  */
657
- declare interface Context {
693
+ interface Context {
658
694
  /**
659
695
  * Indicates whether the text area supports formatting.
660
696
  */
@@ -699,7 +735,7 @@ declare interface Context {
699
735
  /**
700
736
  * Represents the current values of the extension's settings.
701
737
  */
702
- declare interface Options {
738
+ interface Options {
703
739
  readonly [identifier: string]: string | boolean;
704
740
  }
705
741
 
@@ -707,7 +743,7 @@ declare interface Options {
707
743
  * The `authsecret` property has the special behaviour of throwing an `Error` with the message 'Not signed in' if it is accessed while either
708
744
  * undefined or holding an empty string.
709
745
  */
710
- declare interface AuthOptions {
746
+ interface AuthOptions {
711
747
  /**
712
748
  * The stored value that was returned from the `auth()` function.
713
749
  */
@@ -718,7 +754,7 @@ declare interface AuthOptions {
718
754
  * This interface describes the methods and properties of the global {@link popclip} object.
719
755
  *
720
756
  */
721
- declare interface PopClip {
757
+ interface PopClip {
722
758
  /**
723
759
  * The state of the modifier keys when the action was invoked in PopClip.
724
760
  *
@@ -930,54 +966,10 @@ declare interface PopClip {
930
966
  ) => void;
931
967
  }
932
968
 
933
- /**
934
- * The global `popclip` object encapsulates the user's current interaction with PopClip, and provides methods
935
- * for performing various actions. It implements {@link PopClip}.
936
- */
937
- declare const popclip: PopClip;
938
-
939
- /**
940
- * Represents a formatted text string. The underlying implementation uses a macOS Attributed String (`NSAttributedString`) object.
941
- * Can be constructed from a plain string in RTF, HTML, or Markdown format.
942
- *
943
- * #### Example
944
- * ```js
945
- * // create a RichString object from a html string
946
- * const item = new RichString("<b>bold</b> and <i>italic</i>.", {format: 'html'});
947
- * // create a RichString object from a markdown string
948
- * const item = new RichString("# Title\n\nBody.", {format: 'markdown'});
949
- * ```
950
- */
951
- declare class RichString {
952
- /**
953
- * Create a new RichString object from a string.
954
- *
955
- * @param source The string to convert to a RichString object.
956
- * @param options Options for the conversion.
957
- */
958
- constructor(
959
- source: string,
960
- options?: {
961
- /**
962
- Format of the source string. Default is 'rtf'.
963
- */
964
- format?: "rtf" | "html" | "markdown";
965
- },
966
- );
967
- /**
968
- * An RTF representation of the content.
969
- */
970
- readonly rtf: string;
971
- /**
972
- * An HTML representation of the content.
973
- */
974
- readonly html: string;
975
- }
976
-
977
969
  /**
978
970
  * A container for various utility functions and constants {@link util} object.
979
971
  */
980
- declare interface Util {
972
+ interface Util {
981
973
  /**
982
974
  * Localize an English string into the current user interface language, if possible.
983
975
  * This will work for strings which match an existing string in PopClip's user interface.
@@ -1114,15 +1106,10 @@ declare interface Util {
1114
1106
  };
1115
1107
  }
1116
1108
 
1117
- /**
1118
- * The global `util` object acts as a container for various utility functions and constants. It implements {@link Util}.
1119
- */
1120
- declare const util: Util;
1121
-
1122
1109
  /**
1123
1110
  * Represents the raw pasteboard content, indexed by UTI. Supports string data only.
1124
1111
  */
1125
- declare interface PasteboardContent {
1112
+ interface PasteboardContent {
1126
1113
  "public.utf8-plain-text"?: string;
1127
1114
  "public.html"?: string;
1128
1115
  "public.rtf"?: string;
@@ -1132,7 +1119,7 @@ declare interface PasteboardContent {
1132
1119
  /**
1133
1120
  * Options for Paste operations.
1134
1121
  */
1135
- declare interface PasteOptions {
1122
+ interface PasteOptions {
1136
1123
  /**
1137
1124
  * Whether to restore the original contents of the pasteboard after the paste
1138
1125
  * operation. Default is `false`.
@@ -1143,7 +1130,7 @@ declare interface PasteOptions {
1143
1130
  /**
1144
1131
  * A simplified interface to the macOS pasteboard. Implemented by the global object, {@link pasteboard}.
1145
1132
  */
1146
- declare interface Pasteboard {
1133
+ interface Pasteboard {
1147
1134
  /**
1148
1135
  * Get and set the plain text content of the pasteboard.
1149
1136
  *
@@ -1170,6 +1157,55 @@ declare interface Pasteboard {
1170
1157
  content: PasteboardContent;
1171
1158
  }
1172
1159
 
1160
+ /**
1161
+ * The global `popclip` object encapsulates the user's current interaction with PopClip, and provides methods
1162
+ * for performing various actions. It implements {@link PopClip}.
1163
+ */
1164
+ declare const popclip: PopClip;
1165
+
1166
+ /**
1167
+ * Represents a formatted text string. The underlying implementation uses a macOS Attributed String (`NSAttributedString`) object.
1168
+ * Can be constructed from a plain string in RTF, HTML, or Markdown format.
1169
+ *
1170
+ * #### Example
1171
+ * ```js
1172
+ * // create a RichString object from a html string
1173
+ * const item = new RichString("<b>bold</b> and <i>italic</i>.", {format: 'html'});
1174
+ * // create a RichString object from a markdown string
1175
+ * const item = new RichString("# Title\n\nBody.", {format: 'markdown'});
1176
+ * ```
1177
+ */
1178
+ declare class RichString {
1179
+ /**
1180
+ * Create a new RichString object from a string.
1181
+ *
1182
+ * @param source The string to convert to a RichString object.
1183
+ * @param options Options for the conversion.
1184
+ */
1185
+ constructor(
1186
+ source: string,
1187
+ options?: {
1188
+ /**
1189
+ Format of the source string. Default is 'rtf'.
1190
+ */
1191
+ format?: "rtf" | "html" | "markdown";
1192
+ },
1193
+ );
1194
+ /**
1195
+ * An RTF representation of the content.
1196
+ */
1197
+ readonly rtf: string;
1198
+ /**
1199
+ * An HTML representation of the content.
1200
+ */
1201
+ readonly html: string;
1202
+ }
1203
+
1204
+ /**
1205
+ * The global `util` object acts as a container for various utility functions and constants. It implements {@link Util}.
1206
+ */
1207
+ declare const util: Util;
1208
+
1173
1209
  /**
1174
1210
  * The global `pasteboard` object provides access to the contents of the macOS general pasteboard (i.e. the system clipboard). It implements {@link Pasteboard}.
1175
1211
  */
@@ -1195,29 +1231,12 @@ declare const pasteboard: Pasteboard;
1195
1231
  */
1196
1232
  declare function print(...args: any[]): void;
1197
1233
 
1198
- /*
1199
- * Export an object for use by another file.
1200
- *
1201
- * #### Notes
1202
- *
1203
- * The _define_ function family exports an arbitrary object, which other files can import using {@link require}.
1204
- *
1205
- * It should be called only once in any file; if it is called more than once, only the
1206
- * final call will have any effect.
1207
- *
1208
- * Partially implements AMD spec: https://github.com/amdjs/amdjs-api/wiki/AMD
1209
- *
1210
- * Recommendation: instead of this, use {@link defineExtension} or `module.exports = ...`.
1234
+ /**
1235
+ * A promise-based sleep function. Included as a more convenient alternative
1236
+ * to {@link setTimeout} for performing simple delays. Call as `await sleep(1000)`.
1237
+ * @param durationMilliseconds How long to sleep in milliseconds
1211
1238
  */
1212
- declare function define(object: object): void;
1213
- declare function define(factory: () => object): void;
1214
- declare function define(dependencies: string[], factory: () => object): void;
1215
- declare function define(id: string, factory: () => object): void;
1216
- declare function define(
1217
- id: string,
1218
- dependencies: string[],
1219
- factory: () => object,
1220
- ): void;
1239
+ declare function sleep(durationMilliseconds: number): Promise<void>;
1221
1240
 
1222
1241
  /**
1223
1242
  * This global function may be called as an alternative to setting `module.exports` directly.
@@ -1233,93 +1252,3 @@ declare function define(
1233
1252
  declare function defineExtension<CustomOptions extends Options = Options>(
1234
1253
  extension: Extension<CustomOptions>,
1235
1254
  ): void;
1236
-
1237
- /* Declare ambient module + exports for CommonJS-style exporting */
1238
- declare const module: { exports: any };
1239
- declare const exports: any;
1240
-
1241
- /**
1242
- * Import an object from another file.
1243
- *
1244
- * #### Notes
1245
- *
1246
- * PopClip's `require()` implementation attempts to import from the following module formats:
1247
- *
1248
- * - AMD modules, which use `define(...)`.
1249
- * - CommonJS modules, which use `module.exports = ...` or `exports.name = ...`
1250
- * - TypeScript-compiled ES modules, which use `exports.default = ...`
1251
- *
1252
- * #### Notes
1253
- *
1254
- * Paths beginning with `./` or `../` are resolved relative to the the location of the current file.
1255
- *
1256
- * Otherwise, the path is resolved relative to the extensions's package root.
1257
- * If there is no file in the extension, PopClip will look in its internal module repository.
1258
- *
1259
- * If no file extension is given, PopCLip will try adding the extensions `.js`, `.ts`, `.json` in that order.
1260
- *
1261
- * TypeScript files are transpiled to JavaScript on the fly.
1262
- *
1263
- * JSON files are parsed and returned as an object.å
1264
- *
1265
- * @param file Path to the file to import.
1266
- * @return The imported object.
1267
- */
1268
- declare function require(file: string): object;
1269
-
1270
- /**
1271
- * A promise-based sleep function. Included as a more convenient alternative
1272
- * to {@link setTimeout} for performing simple delays. Call as `await sleep(1000)`.
1273
- * @param durationMilliseconds How long to sleep in milliseconds
1274
- */
1275
- declare function sleep(durationMilliseconds: number): Promise<void>;
1276
-
1277
- /* WebAPI and Node.js Globals
1278
- * The following functions and objects are available in PopClip via polyfills.
1279
- */
1280
-
1281
- /**
1282
- * Call a function after a specified time interval.
1283
- *
1284
- * #### Notes
1285
- *
1286
- * This is PopClip's own implementation of the standard
1287
- * [setTimeout](http://developer.mozilla.org/en-US/docs/Web/API/SetTimeout) function,
1288
- * as found in browsers.
1289
- * Ordinarily you shouldn't need to use this. It is is mainly included for
1290
- * compatibility with libraries that might need it.
1291
- *
1292
- * @param callback A function to be called after the timer expires.
1293
- * @param timeout Timeout in milliseconds. If this parameter is omitted, a value of 0 is used,
1294
- * @param args Additional arguments to be passed to the callback function.
1295
- * @returns Numeric identifier for the timer which can be passed to {@link clearTimeout} to cancel it.
1296
- */
1297
- declare function setTimeout(
1298
- callback: (...args: any) => void,
1299
- timeout?: number,
1300
- ...args: any
1301
- ): number;
1302
-
1303
- /**
1304
- * Cancels a timeout prevouly created with {@link setTimeout}.
1305
- * @param timeoutId Identifier of the timeout to cancel.
1306
- */
1307
- declare function clearTimeout(timeoutId: number): void;
1308
-
1309
- // these are from WebAPI, and are implemented in PopClip with polyfills from `core-js` library
1310
- declare function btoa(string: string): string;
1311
- declare function atob(string: string): string;
1312
- declare function structuredClone<T>(value: T): T;
1313
- declare const URL: any;
1314
- declare const URLSearchParams: any;
1315
-
1316
- // XMLHttpRequest is implemented natively in PopClip
1317
- declare const XMLHttpRequest: any;
1318
-
1319
- // Blob is is a WebAPI object, implemented in PopClip with 'node-blob` library
1320
- declare const Blob: any;
1321
-
1322
- // Buffer is a node.js object, implemented in PopClip with 'buffer' library
1323
- declare const Buffer: any;
1324
-
1325
- // TODO: Not sure how to improve typings for these imported globals?