yavascript 0.0.9 → 0.0.10

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": "yavascript",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "main": "lib/index.js",
5
5
  "bin": "lib/cli.js",
6
6
  "types": "yavascript.d.ts",
package/yavascript.d.ts CHANGED
@@ -128,19 +128,10 @@ declare const env: { [key: string]: string | undefined };
128
128
  * Anything that appears after `--` is considered a positional argument instead
129
129
  * of a flag. `--` is not present in the returned positional arguments Array.
130
130
  *
131
- * Single-character flags must have a single leading dash, and multi-character
132
- * flags must have two leading dashes.
133
- *
134
- * Flags with equals signs in them (eg. `--something=42`) are not supported.
135
- * Write `--something 42` instead.
136
- *
137
- * Flags where you specify them multiple times, like `-vvv`, are not supported.
138
- * Write something like `-v 3` instead.
139
- *
140
131
  * @param hints - An object whose keys are flag names (in camelCase) and whose values indicate what type to treat that flag as. Valid property values are `String`, `Boolean`, `Number`, and `Path`. `Path` will resolve relative paths into absolute paths for you. If no hints object is specified, `parseScriptArgs` will do its best to guess, based on the command-line args.
141
132
  * @param argv - An array containing the command line flags you want to parse. If unspecified, `scriptArgs.slice(2)` will be used (we slice 2 in order to skip the yavascript binary and script name). If you pass in an array here, it should only contain command-line flags, not the binary being called.
142
133
  *
143
- * @returns An object with two properties: `flags` and `args`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, or numbers corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line.
134
+ * @returns An object with three properties: `flags`, `args`, and `metadata`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, numbers, or `Path`s corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line. `metadata` contains information about what name and type the flags got mapped to.
144
135
  */
145
136
  declare function parseScriptArgs(
146
137
  hints?: {
@@ -150,6 +141,17 @@ declare function parseScriptArgs(
150
141
  ): {
151
142
  flags: { [key: string]: any };
152
143
  args: Array<string>;
144
+ metadata: {
145
+ keys: {
146
+ [key: string]: string | undefined;
147
+ };
148
+ hints: {
149
+ [key: string]: string | undefined;
150
+ };
151
+ guesses: {
152
+ [key: string]: string | undefined;
153
+ };
154
+ };
153
155
  };
154
156
 
155
157
  /**
@@ -187,6 +189,11 @@ declare function writeFile(
187
189
  data: string | ArrayBuffer
188
190
  ): void;
189
191
 
192
+ /**
193
+ * Function which returns true if the path points to a regular file.
194
+ */
195
+ declare function isFile(path: string | Path): boolean;
196
+
190
197
  /**
191
198
  * Function which returns true if the path points to a directory, or if the
192
199
  * path points to a symlink which points to a directory. Otherwise, it returns
@@ -199,6 +206,28 @@ declare function isDir(path: string | Path): boolean;
199
206
  */
200
207
  declare function isLink(path: string | Path): boolean;
201
208
 
209
+ /**
210
+ * Returns true if the resource at the provided path can be executed by the
211
+ * current user.
212
+ *
213
+ * If nothing exists at that path, an error will be thrown.
214
+ */
215
+ declare function isExecutable(path: string | Path): boolean;
216
+
217
+ /**
218
+ * Returns true if the resource at the provided path can be read by the current
219
+ * user.
220
+ *
221
+ * If nothing exists at that path, an error will be thrown.
222
+ */
223
+ declare function isReadable(path: string | Path): boolean;
224
+
225
+ /**
226
+ * Returns true if a resource at the provided path could be written to by the
227
+ * current user.
228
+ */
229
+ declare function isWritable(path: string | Path): boolean;
230
+
202
231
  /**
203
232
  * Delete the file or directory at the specified path.
204
233
  *
@@ -562,6 +591,40 @@ declare function readlink(path: string | Path): string;
562
591
  */
563
592
  declare function realpath(path: string | Path): string;
564
593
 
594
+ /**
595
+ * Blocks the current thread for at least the specified number of milliseconds,
596
+ * or maybe a tiny bit longer.
597
+ *
598
+ * alias for `sleep.sync`.
599
+ */
600
+ declare var sleep: {
601
+ /**
602
+ * Blocks the current thread for at least the specified number of milliseconds,
603
+ * or maybe a tiny bit longer.
604
+ *
605
+ * alias for `sleep.sync`.
606
+ *
607
+ * @param milliseconds - The number of milliseconds to block for.
608
+ */
609
+ (milliseconds: number): void;
610
+
611
+ /**
612
+ * Blocks the current thread for at least the specified number of milliseconds,
613
+ * or maybe a tiny bit longer.
614
+ *
615
+ * @param milliseconds - The number of milliseconds to block for.
616
+ */
617
+ sync(milliseconds: number): void;
618
+
619
+ /**
620
+ * Returns a Promise which resolves in at least the specified number of
621
+ * milliseconds, maybe a little longer.
622
+ *
623
+ * @param milliseconds - The number of milliseconds to wait before the returned Promise should be resolved.
624
+ */
625
+ async(milliseconds: number): Promise<void>;
626
+ };
627
+
565
628
  /**
566
629
  * If the file at `path` exists, update its creation/modification timestamps.
567
630
  *
@@ -598,33 +661,19 @@ declare type BaseExecOptions = {
598
661
  failOnNonZeroStatus?: boolean;
599
662
 
600
663
  /**
601
- * If true, stdout and stderr will be collected into strings and returned
602
- * instead of being printed to the screen.
664
+ * If true, stdout and stderr will be collected into strings or array buffers
665
+ * and returned instead of being printed to the screen.
603
666
  *
604
- * Defaults to false.
667
+ * Defaults to false. true is an alias for "utf8".
605
668
  */
606
- captureOutput?: boolean;
669
+ captureOutput?: boolean | "utf8" | "arraybuffer";
607
670
  };
608
671
 
609
672
  declare interface Exec {
610
- (args: Array<string> | string, options?: BaseExecOptions): void;
611
-
612
673
  (
613
674
  args: Array<string> | string,
614
675
  options: BaseExecOptions & {
615
- /**
616
- * Whether an Error should be thrown when the process exits with a nonzero
617
- * status code.
618
- *
619
- * Defaults to true.
620
- */
621
676
  failOnNonZeroStatus: true;
622
- /**
623
- * If true, stdout and stderr will be collected into strings and returned
624
- * instead of being printed to the screen.
625
- *
626
- * Defaults to false.
627
- */
628
677
  captureOutput: false;
629
678
  }
630
679
  ): void;
@@ -632,19 +681,7 @@ declare interface Exec {
632
681
  (
633
682
  args: Array<string> | string,
634
683
  options: BaseExecOptions & {
635
- /**
636
- * Whether an Error should be thrown when the process exits with a nonzero
637
- * status code.
638
- *
639
- * Defaults to true.
640
- */
641
684
  failOnNonZeroStatus: false;
642
- /**
643
- * If true, stdout and stderr will be collected into strings and returned
644
- * instead of being printed to the screen.
645
- *
646
- * Defaults to false.
647
- */
648
685
  captureOutput: false;
649
686
  }
650
687
  ):
@@ -654,12 +691,70 @@ declare interface Exec {
654
691
  (
655
692
  args: Array<string> | string,
656
693
  options: BaseExecOptions & {
657
- /**
658
- * Whether an Error should be thrown when the process exits with a nonzero
659
- * status code.
660
- *
661
- * Defaults to true.
662
- */
694
+ failOnNonZeroStatus: true;
695
+ captureOutput: true;
696
+ }
697
+ ): { stdout: string; stderr: string };
698
+
699
+ (
700
+ args: Array<string> | string,
701
+ options: BaseExecOptions & {
702
+ failOnNonZeroStatus: true;
703
+ captureOutput: "utf8";
704
+ }
705
+ ): { stdout: string; stderr: string };
706
+
707
+ (
708
+ args: Array<string> | string,
709
+ options: BaseExecOptions & {
710
+ failOnNonZeroStatus: true;
711
+ captureOutput: "arraybuffer";
712
+ }
713
+ ): { stdout: ArrayBuffer; stderr: ArrayBuffer };
714
+
715
+ (
716
+ args: Array<string> | string,
717
+ options: BaseExecOptions & {
718
+ failOnNonZeroStatus: false;
719
+ captureOutput: true;
720
+ }
721
+ ):
722
+ | { stdout: string; stderr: string; status: number; signal: undefined }
723
+ | { stdout: string; stderr: string; status: undefined; signal: number };
724
+
725
+ (
726
+ args: Array<string> | string,
727
+ options: BaseExecOptions & {
728
+ failOnNonZeroStatus: false;
729
+ captureOutput: "utf-8";
730
+ }
731
+ ):
732
+ | { stdout: string; stderr: string; status: number; signal: undefined }
733
+ | { stdout: string; stderr: string; status: undefined; signal: number };
734
+
735
+ (
736
+ args: Array<string> | string,
737
+ options: BaseExecOptions & {
738
+ failOnNonZeroStatus: false;
739
+ captureOutput: "arraybuffer";
740
+ }
741
+ ):
742
+ | {
743
+ stdout: ArrayBuffer;
744
+ stderr: ArrayBuffer;
745
+ status: number;
746
+ signal: undefined;
747
+ }
748
+ | {
749
+ stdout: ArrayBuffer;
750
+ stderr: ArrayBuffer;
751
+ status: undefined;
752
+ signal: number;
753
+ };
754
+
755
+ (
756
+ args: Array<string> | string,
757
+ options: BaseExecOptions & {
663
758
  failOnNonZeroStatus: true;
664
759
  }
665
760
  ): void;
@@ -667,12 +762,6 @@ declare interface Exec {
667
762
  (
668
763
  args: Array<string> | string,
669
764
  options: BaseExecOptions & {
670
- /**
671
- * Whether an Error should be thrown when the process exits with a nonzero
672
- * status code.
673
- *
674
- * Defaults to true.
675
- */
676
765
  failOnNonZeroStatus: false;
677
766
  }
678
767
  ):
@@ -682,19 +771,6 @@ declare interface Exec {
682
771
  (
683
772
  args: Array<string> | string,
684
773
  options: BaseExecOptions & {
685
- /**
686
- * Whether an Error should be thrown when the process exits with a nonzero
687
- * status code.
688
- *
689
- * Defaults to true.
690
- */
691
- failOnNonZeroStatus: true;
692
- /**
693
- * If true, stdout and stderr will be collected into strings and returned
694
- * instead of being printed to the screen.
695
- *
696
- * Defaults to false.
697
- */
698
774
  captureOutput: true;
699
775
  }
700
776
  ): { stdout: string; stderr: string };
@@ -702,44 +778,25 @@ declare interface Exec {
702
778
  (
703
779
  args: Array<string> | string,
704
780
  options: BaseExecOptions & {
705
- /**
706
- * If true, stdout and stderr will be collected into strings and returned
707
- * instead of being printed to the screen.
708
- *
709
- * Defaults to false.
710
- */
711
- captureOutput: true;
781
+ captureOutput: "utf8";
712
782
  }
713
783
  ): { stdout: string; stderr: string };
714
784
 
715
785
  (
716
786
  args: Array<string> | string,
717
787
  options: BaseExecOptions & {
718
- /**
719
- * If true, stdout and stderr will be collected into strings and returned
720
- * instead of being printed to the screen.
721
- *
722
- * Defaults to false.
723
- */
724
- captureOutput: false;
788
+ captureOutput: "arraybuffer";
725
789
  }
726
- ): void;
790
+ ): { stdout: ArrayBuffer; stderr: ArrayBuffer };
727
791
 
728
792
  (
729
793
  args: Array<string> | string,
730
794
  options: BaseExecOptions & {
731
- /**
732
- * Whether an Error should be thrown when the process exits with a nonzero
733
- * status code.
734
- *
735
- * Defaults to true.
736
- */
737
- failOnNonZeroStatus: false;
738
- captureOutput: true;
795
+ captureOutput: false;
739
796
  }
740
- ):
741
- | { stdout: string; stderr: string; status: number; signal: undefined }
742
- | { stdout: string; stderr: string; status: undefined; signal: number };
797
+ ): void;
798
+
799
+ (args: Array<string> | string, options?: BaseExecOptions): void;
743
800
  }
744
801
 
745
802
  /** Runs a child process using the provided arguments. The first value in the arguments array is the program to run. */
@@ -1026,7 +1083,11 @@ declare const grepString: {
1026
1083
  str: string,
1027
1084
  pattern: string | RegExp,
1028
1085
  options: { inverse: true; details: true }
1029
- ): Array<string>;
1086
+ ): Array<{
1087
+ lineNumber: number;
1088
+ lineContent: string;
1089
+ matches: RegExpMatchArray;
1090
+ }>;
1030
1091
  };
1031
1092
 
1032
1093
  /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
@@ -1092,7 +1153,11 @@ declare const grepFile: {
1092
1153
  path: string | Path,
1093
1154
  pattern: string | RegExp,
1094
1155
  options: { inverse: true; details: true }
1095
- ): Array<string>;
1156
+ ): Array<{
1157
+ lineNumber: number;
1158
+ lineContent: string;
1159
+ matches: RegExpMatchArray;
1160
+ }>;
1096
1161
  };
1097
1162
 
1098
1163
  interface String {
@@ -1139,7 +1204,11 @@ interface String {
1139
1204
  (
1140
1205
  pattern: string | RegExp,
1141
1206
  options: { inverse: true; details: true }
1142
- ): Array<string>;
1207
+ ): Array<{
1208
+ lineNumber: number;
1209
+ lineContent: string;
1210
+ matches: RegExpMatchArray;
1211
+ }>;
1143
1212
  };
1144
1213
  }
1145
1214
 
@@ -2675,21 +2744,20 @@ declare const startRepl: {
2675
2744
  */
2676
2745
  declare class GitRepo {
2677
2746
  /**
2678
- * Given a path to a file or folder on disk, finds the parent git repo
2679
- * containing that path, and returns the absolute path to the repo root (the
2680
- * folder that contains the '.git' folder).
2681
- *
2682
- * This is done by running `git rev-parse --show-toplevel`.
2747
+ * Given a path to a file or folder on disk, searches upwards through the
2748
+ * directory ancestry to find a `.git` folder, then returns the Path that
2749
+ * contains that `.git` folder. If no `.git` folder is found, an error will be
2750
+ * thrown.
2683
2751
  */
2684
2752
  static findRoot(fromPath: string | Path): Path;
2685
2753
 
2686
2754
  /**
2687
- * Creates a new `Git` object for the given repo on disk.
2755
+ * Creates a new `GitRepo` object for the given repo on disk.
2688
2756
  */
2689
2757
  constructor(repoDir: string | Path);
2690
2758
 
2691
2759
  /**
2692
- * The root folder of the git repo that this `Git` object represents (the
2760
+ * The root folder of the git repo that this `GitRepo` object represents (the
2693
2761
  * folder that contains the '.git' folder).
2694
2762
  */
2695
2763
  repoDir: Path;
@@ -2721,7 +2789,7 @@ declare class GitRepo {
2721
2789
  /**
2722
2790
  * Returns whether the provided path is ignored by git.
2723
2791
  *
2724
- * If `path` is an absolute path, it must be a child directory of this Git
2792
+ * If `path` is an absolute path, it must be a child directory of this GitRepo
2725
2793
  * object's `repoDir`, or else an error will be thrown.
2726
2794
  */
2727
2795
  isIgnored(path: string | Path): boolean;
@@ -4100,6 +4168,38 @@ declare module "quickjs:std" {
4100
4168
  /** Return an object containing the environment variables as key-value pairs. */
4101
4169
  export function getenviron(): { [key: string]: string | undefined };
4102
4170
 
4171
+ /**
4172
+ * Return the real user ID of the calling process.
4173
+ *
4174
+ * This function throws an error on windows, because windows doesn't support
4175
+ * the same uid/gid paradigm as Unix-like operating systems.
4176
+ */
4177
+ export function getuid(): number;
4178
+
4179
+ /**
4180
+ * Return the effective user ID of the calling process.
4181
+ *
4182
+ * This function throws an error on windows, because windows doesn't support
4183
+ * the same uid/gid paradigm as Unix-like operating systems.
4184
+ */
4185
+ export function geteuid(): number;
4186
+
4187
+ /**
4188
+ * Return the real group ID of the calling process.
4189
+ *
4190
+ * This function throws an error on windows, because windows doesn't support
4191
+ * the same uid/gid paradigm as Unix-like operating systems.
4192
+ */
4193
+ export function getgid(): number;
4194
+
4195
+ /**
4196
+ * Return the effective group ID of the calling process.
4197
+ *
4198
+ * This function throws an error on windows, because windows doesn't support
4199
+ * the same uid/gid paradigm as Unix-like operating systems.
4200
+ */
4201
+ export function getegid(): number;
4202
+
4103
4203
  interface UrlGet {
4104
4204
  /**
4105
4205
  * Download `url` using the `curl` command line utility. Returns string
@@ -4217,6 +4317,20 @@ declare module "quickjs:std" {
4217
4317
  * - octal (0o prefix) and hexadecimal (0x prefix) numbers
4218
4318
  */
4219
4319
  export function parseExtJSON(str: string): any;
4320
+
4321
+ /**
4322
+ * A wrapper around the standard C [strftime](https://en.cppreference.com/w/c/chrono/strftime).
4323
+ * Formats a time/date into a format as specified by the user.
4324
+ *
4325
+ * @param maxBytes - The number of bytes to allocate for the string that will be returned
4326
+ * @param format - Format string, using `%`-prefixed sequences as found in [this table](https://en.cppreference.com/w/c/chrono/strftime#Format_string).
4327
+ * @param time - The Date object (or unix timestamp, in ms) to render.
4328
+ */
4329
+ export function strftime(
4330
+ maxBytes: number,
4331
+ format: string,
4332
+ time: Date | number
4333
+ ): string;
4220
4334
  }
4221
4335
 
4222
4336
  declare module "quickjs:os" {
@@ -5053,6 +5167,10 @@ interface RequireFunction {
5053
5167
 
5054
5168
  declare var require: RequireFunction;
5055
5169
 
5170
+ interface ImportMeta {
5171
+ require: RequireFunction;
5172
+ }
5173
+
5056
5174
  declare var setTimeout: typeof import("quickjs:os").setTimeout;
5057
5175
  declare var clearTimeout: typeof import("quickjs:os").clearTimeout;
5058
5176
 
@@ -5319,3 +5437,6 @@ declare module "quickjs:context" {
5319
5437
  eval(code: string): any;
5320
5438
  }
5321
5439
  }
5440
+
5441
+ declare const std: typeof import("quickjs:std");
5442
+ declare const os: typeof import("quickjs:os");