track-cli 3.0.0-rc
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/LICENSE +7 -0
- package/README.md +3 -0
- package/esm/_dnt.polyfills.d.ts +6 -0
- package/esm/_dnt.polyfills.js +1 -0
- package/esm/_dnt.shims.d.ts +19 -0
- package/esm/_dnt.shims.js +78 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.js +473 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.js +18 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.js +8 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.js +12 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.d.ts +50 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.js +545 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.d.ts +55 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.js +57 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.d.ts +38 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.js +93 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.d.ts +22 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.js +28 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.d.ts +49 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.js +60 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.d.ts +43 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.d.ts +21 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.js +29 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.js +44 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.js +38 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.js +474 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.d.ts +15 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.js +96 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.d.ts +35 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.js +80 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.d.ts +51 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.js +244 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.js +74 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.d.ts +27 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.js +55 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.d.ts +33 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.js +75 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.js +43 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.js +68 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.js +53 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.d.ts +102 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.js +163 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.d.ts +37 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.js +216 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.d.ts +16 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.js +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.d.ts +29 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.js +88 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.js +158 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.d.ts +39 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.js +46 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.js +3 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.d.ts +11 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.js +161 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.js +36 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.d.ts +83 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.js +361 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.d.ts +9 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.js +33 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.d.ts +86 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.js +442 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.js +5 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.d.ts +91 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.js +909 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.js +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.d.ts +76 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.js +154 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.d.ts +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.js +105 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.d.ts +831 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.js +1701 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.js +201 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.js +141 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.d.ts +21 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.js +285 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.d.ts +8 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.js +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.d.ts +45 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.js +323 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.js +34 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.js +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.d.ts +41 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.js +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.js +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.js +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.js +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.js +29 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.js +12 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.d.ts +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.js +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.d.ts +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.js +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.js +55 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.js +102 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.js +75 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.d.ts +60 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.js +117 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.js +106 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.js +157 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.d.ts +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.d.ts +33 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.js +402 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.js +11 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.js +4 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.d.ts +59 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.d.ts +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.js +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.d.ts +78 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.js +128 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.d.ts +99 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.js +529 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.d.ts +49 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.js +74 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.d.ts +135 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.js +237 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.d.ts +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.js +60 -0
- package/esm/package.json +3 -0
- package/esm/src/action/add.d.ts +1 -0
- package/esm/src/action/add.js +57 -0
- package/esm/src/action/clone.d.ts +6 -0
- package/esm/src/action/clone.js +108 -0
- package/esm/src/action/lang.d.ts +1 -0
- package/esm/src/action/lang.js +40 -0
- package/esm/src/action/pull.d.ts +1 -0
- package/esm/src/action/pull.js +22 -0
- package/esm/src/action/remove.d.ts +4 -0
- package/esm/src/action/remove.js +67 -0
- package/esm/src/action/reset.d.ts +1 -0
- package/esm/src/action/reset.js +21 -0
- package/esm/src/action/run.d.ts +4 -0
- package/esm/src/action/run.js +163 -0
- package/esm/src/action/status.d.ts +1 -0
- package/esm/src/action/status.js +5 -0
- package/esm/src/main.d.ts +2 -0
- package/esm/src/main.js +96 -0
- package/esm/src/meta.d.ts +3 -0
- package/esm/src/meta.js +51 -0
- package/esm/src/orca/client.d.ts +20 -0
- package/esm/src/orca/client.js +152 -0
- package/esm/src/orca/types.d.ts +54 -0
- package/esm/src/orca/types.js +12 -0
- package/esm/src/shared/config.d.ts +24 -0
- package/esm/src/shared/config.js +24 -0
- package/esm/src/shared/errors.d.ts +82 -0
- package/esm/src/shared/errors.js +228 -0
- package/esm/src/shared/file.d.ts +30 -0
- package/esm/src/shared/file.js +110 -0
- package/esm/src/shared/mod.d.ts +40 -0
- package/esm/src/shared/mod.js +383 -0
- package/esm/src/shared/types.d.ts +12 -0
- package/esm/src/shared/types.js +1 -0
- package/esm/src/track/client.d.ts +60 -0
- package/esm/src/track/client.js +268 -0
- package/esm/src/track/types.d.ts +210 -0
- package/esm/src/track/types.js +40 -0
- package/package.json +35 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
// A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
|
|
4
|
+
// on npm.
|
|
5
|
+
/**
|
|
6
|
+
* String formatters and utilities for dealing with ANSI color codes.
|
|
7
|
+
*
|
|
8
|
+
* This module is browser compatible.
|
|
9
|
+
*
|
|
10
|
+
* This module supports `NO_COLOR` environmental variable disabling any coloring
|
|
11
|
+
* if `NO_COLOR` is set.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import {
|
|
16
|
+
* bgBlue,
|
|
17
|
+
* bgRgb24,
|
|
18
|
+
* bgRgb8,
|
|
19
|
+
* bold,
|
|
20
|
+
* italic,
|
|
21
|
+
* red,
|
|
22
|
+
* rgb24,
|
|
23
|
+
* rgb8,
|
|
24
|
+
* } from "https://deno.land/std@$STD_VERSION/fmt/colors.ts";
|
|
25
|
+
*
|
|
26
|
+
* console.log(bgBlue(italic(red(bold("Hello, World!")))));
|
|
27
|
+
*
|
|
28
|
+
* // also supports 8bit colors
|
|
29
|
+
*
|
|
30
|
+
* console.log(rgb8("Hello, World!", 42));
|
|
31
|
+
*
|
|
32
|
+
* console.log(bgRgb8("Hello, World!", 42));
|
|
33
|
+
*
|
|
34
|
+
* // and 24bit rgb
|
|
35
|
+
*
|
|
36
|
+
* console.log(rgb24("Hello, World!", {
|
|
37
|
+
* r: 41,
|
|
38
|
+
* g: 42,
|
|
39
|
+
* b: 43,
|
|
40
|
+
* }));
|
|
41
|
+
*
|
|
42
|
+
* console.log(bgRgb24("Hello, World!", {
|
|
43
|
+
* r: 41,
|
|
44
|
+
* g: 42,
|
|
45
|
+
* b: 43,
|
|
46
|
+
* }));
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @module
|
|
50
|
+
*/
|
|
51
|
+
// deno-lint-ignore no-explicit-any
|
|
52
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
53
|
+
const { Deno } = dntShim.dntGlobalThis;
|
|
54
|
+
const noColor = typeof Deno?.noColor === "boolean"
|
|
55
|
+
? Deno.noColor
|
|
56
|
+
: false;
|
|
57
|
+
let enabled = !noColor;
|
|
58
|
+
/**
|
|
59
|
+
* Set changing text color to enabled or disabled
|
|
60
|
+
* @param value
|
|
61
|
+
*/
|
|
62
|
+
export function setColorEnabled(value) {
|
|
63
|
+
if (Deno?.noColor) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
enabled = value;
|
|
67
|
+
}
|
|
68
|
+
/** Get whether text color change is enabled or disabled. */
|
|
69
|
+
export function getColorEnabled() {
|
|
70
|
+
return enabled;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Builds color code
|
|
74
|
+
* @param open
|
|
75
|
+
* @param close
|
|
76
|
+
*/
|
|
77
|
+
function code(open, close) {
|
|
78
|
+
return {
|
|
79
|
+
open: `\x1b[${open.join(";")}m`,
|
|
80
|
+
close: `\x1b[${close}m`,
|
|
81
|
+
regexp: new RegExp(`\\x1b\\[${close}m`, "g"),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Applies color and background based on color code and its associated text
|
|
86
|
+
* @param str text to apply color settings to
|
|
87
|
+
* @param code color code to apply
|
|
88
|
+
*/
|
|
89
|
+
function run(str, code) {
|
|
90
|
+
return enabled
|
|
91
|
+
? `${code.open}${str.replace(code.regexp, code.open)}${code.close}`
|
|
92
|
+
: str;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Reset the text modified
|
|
96
|
+
* @param str text to reset
|
|
97
|
+
*/
|
|
98
|
+
export function reset(str) {
|
|
99
|
+
return run(str, code([0], 0));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Make the text bold.
|
|
103
|
+
* @param str text to make bold
|
|
104
|
+
*/
|
|
105
|
+
export function bold(str) {
|
|
106
|
+
return run(str, code([1], 22));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The text emits only a small amount of light.
|
|
110
|
+
* @param str text to dim
|
|
111
|
+
*/
|
|
112
|
+
export function dim(str) {
|
|
113
|
+
return run(str, code([2], 22));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Make the text italic.
|
|
117
|
+
* @param str text to make italic
|
|
118
|
+
*/
|
|
119
|
+
export function italic(str) {
|
|
120
|
+
return run(str, code([3], 23));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Make the text underline.
|
|
124
|
+
* @param str text to underline
|
|
125
|
+
*/
|
|
126
|
+
export function underline(str) {
|
|
127
|
+
return run(str, code([4], 24));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Invert background color and text color.
|
|
131
|
+
* @param str text to invert its color
|
|
132
|
+
*/
|
|
133
|
+
export function inverse(str) {
|
|
134
|
+
return run(str, code([7], 27));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Make the text hidden.
|
|
138
|
+
* @param str text to hide
|
|
139
|
+
*/
|
|
140
|
+
export function hidden(str) {
|
|
141
|
+
return run(str, code([8], 28));
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Put horizontal line through the center of the text.
|
|
145
|
+
* @param str text to strike through
|
|
146
|
+
*/
|
|
147
|
+
export function strikethrough(str) {
|
|
148
|
+
return run(str, code([9], 29));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Set text color to black.
|
|
152
|
+
* @param str text to make black
|
|
153
|
+
*/
|
|
154
|
+
export function black(str) {
|
|
155
|
+
return run(str, code([30], 39));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Set text color to red.
|
|
159
|
+
* @param str text to make red
|
|
160
|
+
*/
|
|
161
|
+
export function red(str) {
|
|
162
|
+
return run(str, code([31], 39));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Set text color to green.
|
|
166
|
+
* @param str text to make green
|
|
167
|
+
*/
|
|
168
|
+
export function green(str) {
|
|
169
|
+
return run(str, code([32], 39));
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Set text color to yellow.
|
|
173
|
+
* @param str text to make yellow
|
|
174
|
+
*/
|
|
175
|
+
export function yellow(str) {
|
|
176
|
+
return run(str, code([33], 39));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Set text color to blue.
|
|
180
|
+
* @param str text to make blue
|
|
181
|
+
*/
|
|
182
|
+
export function blue(str) {
|
|
183
|
+
return run(str, code([34], 39));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Set text color to magenta.
|
|
187
|
+
* @param str text to make magenta
|
|
188
|
+
*/
|
|
189
|
+
export function magenta(str) {
|
|
190
|
+
return run(str, code([35], 39));
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Set text color to cyan.
|
|
194
|
+
* @param str text to make cyan
|
|
195
|
+
*/
|
|
196
|
+
export function cyan(str) {
|
|
197
|
+
return run(str, code([36], 39));
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Set text color to white.
|
|
201
|
+
* @param str text to make white
|
|
202
|
+
*/
|
|
203
|
+
export function white(str) {
|
|
204
|
+
return run(str, code([37], 39));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Set text color to gray.
|
|
208
|
+
* @param str text to make gray
|
|
209
|
+
*/
|
|
210
|
+
export function gray(str) {
|
|
211
|
+
return brightBlack(str);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Set text color to bright black.
|
|
215
|
+
* @param str text to make bright-black
|
|
216
|
+
*/
|
|
217
|
+
export function brightBlack(str) {
|
|
218
|
+
return run(str, code([90], 39));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Set text color to bright red.
|
|
222
|
+
* @param str text to make bright-red
|
|
223
|
+
*/
|
|
224
|
+
export function brightRed(str) {
|
|
225
|
+
return run(str, code([91], 39));
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Set text color to bright green.
|
|
229
|
+
* @param str text to make bright-green
|
|
230
|
+
*/
|
|
231
|
+
export function brightGreen(str) {
|
|
232
|
+
return run(str, code([92], 39));
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Set text color to bright yellow.
|
|
236
|
+
* @param str text to make bright-yellow
|
|
237
|
+
*/
|
|
238
|
+
export function brightYellow(str) {
|
|
239
|
+
return run(str, code([93], 39));
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Set text color to bright blue.
|
|
243
|
+
* @param str text to make bright-blue
|
|
244
|
+
*/
|
|
245
|
+
export function brightBlue(str) {
|
|
246
|
+
return run(str, code([94], 39));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Set text color to bright magenta.
|
|
250
|
+
* @param str text to make bright-magenta
|
|
251
|
+
*/
|
|
252
|
+
export function brightMagenta(str) {
|
|
253
|
+
return run(str, code([95], 39));
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Set text color to bright cyan.
|
|
257
|
+
* @param str text to make bright-cyan
|
|
258
|
+
*/
|
|
259
|
+
export function brightCyan(str) {
|
|
260
|
+
return run(str, code([96], 39));
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Set text color to bright white.
|
|
264
|
+
* @param str text to make bright-white
|
|
265
|
+
*/
|
|
266
|
+
export function brightWhite(str) {
|
|
267
|
+
return run(str, code([97], 39));
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Set background color to black.
|
|
271
|
+
* @param str text to make its background black
|
|
272
|
+
*/
|
|
273
|
+
export function bgBlack(str) {
|
|
274
|
+
return run(str, code([40], 49));
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Set background color to red.
|
|
278
|
+
* @param str text to make its background red
|
|
279
|
+
*/
|
|
280
|
+
export function bgRed(str) {
|
|
281
|
+
return run(str, code([41], 49));
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Set background color to green.
|
|
285
|
+
* @param str text to make its background green
|
|
286
|
+
*/
|
|
287
|
+
export function bgGreen(str) {
|
|
288
|
+
return run(str, code([42], 49));
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Set background color to yellow.
|
|
292
|
+
* @param str text to make its background yellow
|
|
293
|
+
*/
|
|
294
|
+
export function bgYellow(str) {
|
|
295
|
+
return run(str, code([43], 49));
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Set background color to blue.
|
|
299
|
+
* @param str text to make its background blue
|
|
300
|
+
*/
|
|
301
|
+
export function bgBlue(str) {
|
|
302
|
+
return run(str, code([44], 49));
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Set background color to magenta.
|
|
306
|
+
* @param str text to make its background magenta
|
|
307
|
+
*/
|
|
308
|
+
export function bgMagenta(str) {
|
|
309
|
+
return run(str, code([45], 49));
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Set background color to cyan.
|
|
313
|
+
* @param str text to make its background cyan
|
|
314
|
+
*/
|
|
315
|
+
export function bgCyan(str) {
|
|
316
|
+
return run(str, code([46], 49));
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Set background color to white.
|
|
320
|
+
* @param str text to make its background white
|
|
321
|
+
*/
|
|
322
|
+
export function bgWhite(str) {
|
|
323
|
+
return run(str, code([47], 49));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Set background color to bright black.
|
|
327
|
+
* @param str text to make its background bright-black
|
|
328
|
+
*/
|
|
329
|
+
export function bgBrightBlack(str) {
|
|
330
|
+
return run(str, code([100], 49));
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Set background color to bright red.
|
|
334
|
+
* @param str text to make its background bright-red
|
|
335
|
+
*/
|
|
336
|
+
export function bgBrightRed(str) {
|
|
337
|
+
return run(str, code([101], 49));
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Set background color to bright green.
|
|
341
|
+
* @param str text to make its background bright-green
|
|
342
|
+
*/
|
|
343
|
+
export function bgBrightGreen(str) {
|
|
344
|
+
return run(str, code([102], 49));
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Set background color to bright yellow.
|
|
348
|
+
* @param str text to make its background bright-yellow
|
|
349
|
+
*/
|
|
350
|
+
export function bgBrightYellow(str) {
|
|
351
|
+
return run(str, code([103], 49));
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Set background color to bright blue.
|
|
355
|
+
* @param str text to make its background bright-blue
|
|
356
|
+
*/
|
|
357
|
+
export function bgBrightBlue(str) {
|
|
358
|
+
return run(str, code([104], 49));
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Set background color to bright magenta.
|
|
362
|
+
* @param str text to make its background bright-magenta
|
|
363
|
+
*/
|
|
364
|
+
export function bgBrightMagenta(str) {
|
|
365
|
+
return run(str, code([105], 49));
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Set background color to bright cyan.
|
|
369
|
+
* @param str text to make its background bright-cyan
|
|
370
|
+
*/
|
|
371
|
+
export function bgBrightCyan(str) {
|
|
372
|
+
return run(str, code([106], 49));
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Set background color to bright white.
|
|
376
|
+
* @param str text to make its background bright-white
|
|
377
|
+
*/
|
|
378
|
+
export function bgBrightWhite(str) {
|
|
379
|
+
return run(str, code([107], 49));
|
|
380
|
+
}
|
|
381
|
+
/* Special Color Sequences */
|
|
382
|
+
/**
|
|
383
|
+
* Clam and truncate color codes
|
|
384
|
+
* @param n
|
|
385
|
+
* @param max number to truncate to
|
|
386
|
+
* @param min number to truncate from
|
|
387
|
+
*/
|
|
388
|
+
function clampAndTruncate(n, max = 255, min = 0) {
|
|
389
|
+
return Math.trunc(Math.max(Math.min(n, max), min));
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Set text color using paletted 8bit colors.
|
|
393
|
+
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
|
394
|
+
* @param str text color to apply paletted 8bit colors to
|
|
395
|
+
* @param color code
|
|
396
|
+
*/
|
|
397
|
+
export function rgb8(str, color) {
|
|
398
|
+
return run(str, code([38, 5, clampAndTruncate(color)], 39));
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Set background color using paletted 8bit colors.
|
|
402
|
+
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
|
403
|
+
* @param str text color to apply paletted 8bit background colors to
|
|
404
|
+
* @param color code
|
|
405
|
+
*/
|
|
406
|
+
export function bgRgb8(str, color) {
|
|
407
|
+
return run(str, code([48, 5, clampAndTruncate(color)], 49));
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Set text color using 24bit rgb.
|
|
411
|
+
* `color` can be a number in range `0x000000` to `0xffffff` or
|
|
412
|
+
* an `Rgb`.
|
|
413
|
+
*
|
|
414
|
+
* To produce the color magenta:
|
|
415
|
+
*
|
|
416
|
+
* ```ts
|
|
417
|
+
* import { rgb24 } from "https://deno.land/std@$STD_VERSION/fmt/colors.ts";
|
|
418
|
+
* rgb24("foo", 0xff00ff);
|
|
419
|
+
* rgb24("foo", {r: 255, g: 0, b: 255});
|
|
420
|
+
* ```
|
|
421
|
+
* @param str text color to apply 24bit rgb to
|
|
422
|
+
* @param color code
|
|
423
|
+
*/
|
|
424
|
+
export function rgb24(str, color) {
|
|
425
|
+
if (typeof color === "number") {
|
|
426
|
+
return run(str, code([38, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 39));
|
|
427
|
+
}
|
|
428
|
+
return run(str, code([
|
|
429
|
+
38,
|
|
430
|
+
2,
|
|
431
|
+
clampAndTruncate(color.r),
|
|
432
|
+
clampAndTruncate(color.g),
|
|
433
|
+
clampAndTruncate(color.b),
|
|
434
|
+
], 39));
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Set background color using 24bit rgb.
|
|
438
|
+
* `color` can be a number in range `0x000000` to `0xffffff` or
|
|
439
|
+
* an `Rgb`.
|
|
440
|
+
*
|
|
441
|
+
* To produce the color magenta:
|
|
442
|
+
*
|
|
443
|
+
* ```ts
|
|
444
|
+
* import { bgRgb24 } from "https://deno.land/std@$STD_VERSION/fmt/colors.ts";
|
|
445
|
+
* bgRgb24("foo", 0xff00ff);
|
|
446
|
+
* bgRgb24("foo", {r: 255, g: 0, b: 255});
|
|
447
|
+
* ```
|
|
448
|
+
* @param str text color to apply 24bit rgb to
|
|
449
|
+
* @param color code
|
|
450
|
+
*/
|
|
451
|
+
export function bgRgb24(str, color) {
|
|
452
|
+
if (typeof color === "number") {
|
|
453
|
+
return run(str, code([48, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 49));
|
|
454
|
+
}
|
|
455
|
+
return run(str, code([
|
|
456
|
+
48,
|
|
457
|
+
2,
|
|
458
|
+
clampAndTruncate(color.r),
|
|
459
|
+
clampAndTruncate(color.g),
|
|
460
|
+
clampAndTruncate(color.b),
|
|
461
|
+
], 49));
|
|
462
|
+
}
|
|
463
|
+
// https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
|
|
464
|
+
const ANSI_PATTERN = new RegExp([
|
|
465
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
466
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
|
|
467
|
+
].join("|"), "g");
|
|
468
|
+
/**
|
|
469
|
+
* Remove ANSI escape codes from the string.
|
|
470
|
+
* @param string to remove ANSI escape codes from
|
|
471
|
+
*/
|
|
472
|
+
export function stripColor(string) {
|
|
473
|
+
return string.replace(ANSI_PATTERN, "");
|
|
474
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface PrettyDurationOptions {
|
|
2
|
+
/**
|
|
3
|
+
* "narrow" for "0d 0h 0m 0s 0ms..."
|
|
4
|
+
* "digital" for "00:00:00:00:000..."
|
|
5
|
+
* "full" for "0 days, 0 hours, 0 minutes,..."
|
|
6
|
+
*/
|
|
7
|
+
style: "narrow" | "digital" | "full";
|
|
8
|
+
/**
|
|
9
|
+
* Whether to ignore zero values.
|
|
10
|
+
* With style="narrow" | "full", all zero values are ignored.
|
|
11
|
+
* With style="digital", only values in the ends are ignored.
|
|
12
|
+
*/
|
|
13
|
+
ignoreZero: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function format(ms: number, options?: Partial<PrettyDurationOptions>): string;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
/**
|
|
4
|
+
* Format milliseconds to time duration.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { format } from "https://deno.land/std@$STD_VERSION/fmt/duration.ts";
|
|
8
|
+
*
|
|
9
|
+
* // "00:00:01:39:674:000:000"
|
|
10
|
+
* format(99674, { style: "digital" });
|
|
11
|
+
*
|
|
12
|
+
* // "0d 0h 1m 39s 674ms 0µs 0ns"
|
|
13
|
+
* format(99674);
|
|
14
|
+
*
|
|
15
|
+
* // "1m 39s 674ms"
|
|
16
|
+
* format(99674, { ignoreZero: true });
|
|
17
|
+
*
|
|
18
|
+
* // "1 minutes, 39 seconds, 674 milliseconds"
|
|
19
|
+
* format(99674, { style: "full", ignoreZero: true });
|
|
20
|
+
* ```
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
const addZero = (num, digits) => String(num).padStart(digits, "0");
|
|
24
|
+
const keyList = {
|
|
25
|
+
d: "days",
|
|
26
|
+
h: "hours",
|
|
27
|
+
m: "minutes",
|
|
28
|
+
s: "seconds",
|
|
29
|
+
ms: "milliseconds",
|
|
30
|
+
us: "microseconds",
|
|
31
|
+
ns: "nanoseconds",
|
|
32
|
+
};
|
|
33
|
+
/** Parse milleseconds into a duration. */
|
|
34
|
+
function millisecondsToDurationObject(ms) {
|
|
35
|
+
// Duration cannot be negative
|
|
36
|
+
const absolute_ms = Math.abs(ms);
|
|
37
|
+
return {
|
|
38
|
+
d: Math.trunc(absolute_ms / 86400000),
|
|
39
|
+
h: Math.trunc(absolute_ms / 3600000) % 24,
|
|
40
|
+
m: Math.trunc(absolute_ms / 60000) % 60,
|
|
41
|
+
s: Math.trunc(absolute_ms / 1000) % 60,
|
|
42
|
+
ms: Math.trunc(absolute_ms) % 1000,
|
|
43
|
+
us: Math.trunc(absolute_ms * 1000) % 1000,
|
|
44
|
+
ns: Math.trunc(absolute_ms * 1000000) % 1000,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function durationArray(duration) {
|
|
48
|
+
return [
|
|
49
|
+
{ type: "d", value: duration.d },
|
|
50
|
+
{ type: "h", value: duration.h },
|
|
51
|
+
{ type: "m", value: duration.m },
|
|
52
|
+
{ type: "s", value: duration.s },
|
|
53
|
+
{ type: "ms", value: duration.ms },
|
|
54
|
+
{ type: "us", value: duration.us },
|
|
55
|
+
{ type: "ns", value: duration.ns },
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
export function format(ms, options = {}) {
|
|
59
|
+
const opt = Object.assign({ style: "narrow", ignoreZero: false }, options);
|
|
60
|
+
const duration = millisecondsToDurationObject(ms);
|
|
61
|
+
const durationArr = durationArray(duration);
|
|
62
|
+
switch (opt.style) {
|
|
63
|
+
case "narrow": {
|
|
64
|
+
if (opt.ignoreZero) {
|
|
65
|
+
return `${durationArr.filter((x) => x.value).map((x) => `${x.value}${x.type === "us" ? "µs" : x.type}`)
|
|
66
|
+
.join(" ")}`;
|
|
67
|
+
}
|
|
68
|
+
return `${durationArr.map((x) => `${x.value}${x.type === "us" ? "µs" : x.type}`)
|
|
69
|
+
.join(" ")}`;
|
|
70
|
+
}
|
|
71
|
+
case "full": {
|
|
72
|
+
if (opt.ignoreZero) {
|
|
73
|
+
return `${durationArr.filter((x) => x.value).map((x) => `${x.value} ${keyList[x.type]}`).join(", ")}`;
|
|
74
|
+
}
|
|
75
|
+
return `${durationArr.map((x) => `${x.value} ${keyList[x.type]}`).join(", ")}`;
|
|
76
|
+
}
|
|
77
|
+
case "digital": {
|
|
78
|
+
const arr = durationArr.map((x) => ["ms", "us", "ns"].includes(x.type)
|
|
79
|
+
? addZero(x.value, 3)
|
|
80
|
+
: addZero(x.value, 2));
|
|
81
|
+
if (opt.ignoreZero) {
|
|
82
|
+
let cont = true;
|
|
83
|
+
while (cont) {
|
|
84
|
+
if (!Number(arr[arr.length - 1]))
|
|
85
|
+
arr.pop();
|
|
86
|
+
else
|
|
87
|
+
cont = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return arr.join(":");
|
|
91
|
+
}
|
|
92
|
+
default: {
|
|
93
|
+
throw new TypeError(`style must be "narrow", "full", or "digital"!`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
3
|
+
/**
|
|
4
|
+
* Test whether `src` and `dest` resolve to the same location
|
|
5
|
+
* @param src src file path
|
|
6
|
+
* @param dest dest file path
|
|
7
|
+
*/
|
|
8
|
+
export declare function isSamePath(src: string | URL, dest: string | URL): boolean | void;
|
|
9
|
+
/**
|
|
10
|
+
* Test whether or not `dest` is a sub-directory of `src`
|
|
11
|
+
* @param src src file path
|
|
12
|
+
* @param dest dest file path
|
|
13
|
+
* @param sep path separator
|
|
14
|
+
*/
|
|
15
|
+
export declare function isSubdir(src: string | URL, dest: string | URL, sep?: string): boolean;
|
|
16
|
+
export type PathType = "file" | "dir" | "symlink";
|
|
17
|
+
/**
|
|
18
|
+
* Get a human readable file type string.
|
|
19
|
+
*
|
|
20
|
+
* @param fileInfo A FileInfo describes a file and is returned by `stat`,
|
|
21
|
+
* `lstat`
|
|
22
|
+
*/
|
|
23
|
+
export declare function getFileInfoType(fileInfo: dntShim.Deno.FileInfo): PathType | undefined;
|
|
24
|
+
export interface WalkEntry extends dntShim.Deno.DirEntry {
|
|
25
|
+
path: string;
|
|
26
|
+
}
|
|
27
|
+
/** Create WalkEntry for the `path` synchronously */
|
|
28
|
+
export declare function createWalkEntrySync(path: string | URL): WalkEntry;
|
|
29
|
+
/** Create WalkEntry for the `path` asynchronously */
|
|
30
|
+
export declare function createWalkEntry(path: string | URL): Promise<WalkEntry>;
|
|
31
|
+
/**
|
|
32
|
+
* Convert a URL or string to a path
|
|
33
|
+
* @param pathUrl A URL or string to be converted
|
|
34
|
+
*/
|
|
35
|
+
export declare function toPathString(pathUrl: string | URL): string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
3
|
+
import * as path from "../path/mod.js";
|
|
4
|
+
import { basename, normalize } from "../path/mod.js";
|
|
5
|
+
/**
|
|
6
|
+
* Test whether `src` and `dest` resolve to the same location
|
|
7
|
+
* @param src src file path
|
|
8
|
+
* @param dest dest file path
|
|
9
|
+
*/
|
|
10
|
+
export function isSamePath(src, dest) {
|
|
11
|
+
src = toPathString(src);
|
|
12
|
+
dest = toPathString(dest);
|
|
13
|
+
return path.resolve(src) === path.resolve(dest);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Test whether or not `dest` is a sub-directory of `src`
|
|
17
|
+
* @param src src file path
|
|
18
|
+
* @param dest dest file path
|
|
19
|
+
* @param sep path separator
|
|
20
|
+
*/
|
|
21
|
+
export function isSubdir(src, dest, sep = path.SEP) {
|
|
22
|
+
if (src === dest) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
src = toPathString(src);
|
|
26
|
+
const srcArray = src.split(sep);
|
|
27
|
+
dest = toPathString(dest);
|
|
28
|
+
const destArray = dest.split(sep);
|
|
29
|
+
return srcArray.every((current, i) => destArray[i] === current);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get a human readable file type string.
|
|
33
|
+
*
|
|
34
|
+
* @param fileInfo A FileInfo describes a file and is returned by `stat`,
|
|
35
|
+
* `lstat`
|
|
36
|
+
*/
|
|
37
|
+
export function getFileInfoType(fileInfo) {
|
|
38
|
+
return fileInfo.isFile
|
|
39
|
+
? "file"
|
|
40
|
+
: fileInfo.isDirectory
|
|
41
|
+
? "dir"
|
|
42
|
+
: fileInfo.isSymlink
|
|
43
|
+
? "symlink"
|
|
44
|
+
: undefined;
|
|
45
|
+
}
|
|
46
|
+
/** Create WalkEntry for the `path` synchronously */
|
|
47
|
+
export function createWalkEntrySync(path) {
|
|
48
|
+
path = toPathString(path);
|
|
49
|
+
path = normalize(path);
|
|
50
|
+
const name = basename(path);
|
|
51
|
+
const info = dntShim.Deno.statSync(path);
|
|
52
|
+
return {
|
|
53
|
+
path,
|
|
54
|
+
name,
|
|
55
|
+
isFile: info.isFile,
|
|
56
|
+
isDirectory: info.isDirectory,
|
|
57
|
+
isSymlink: info.isSymlink,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Create WalkEntry for the `path` asynchronously */
|
|
61
|
+
export async function createWalkEntry(path) {
|
|
62
|
+
path = toPathString(path);
|
|
63
|
+
path = normalize(path);
|
|
64
|
+
const name = basename(path);
|
|
65
|
+
const info = await dntShim.Deno.stat(path);
|
|
66
|
+
return {
|
|
67
|
+
path,
|
|
68
|
+
name,
|
|
69
|
+
isFile: info.isFile,
|
|
70
|
+
isDirectory: info.isDirectory,
|
|
71
|
+
isSymlink: info.isSymlink,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Convert a URL or string to a path
|
|
76
|
+
* @param pathUrl A URL or string to be converted
|
|
77
|
+
*/
|
|
78
|
+
export function toPathString(pathUrl) {
|
|
79
|
+
return pathUrl instanceof URL ? path.fromFileUrl(pathUrl) : pathUrl;
|
|
80
|
+
}
|