starship-butler-utils 0.3.3 → 0.3.5
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/dist/index.d.ts +10 -3
- package/dist/index.js +17 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -25,8 +25,6 @@ declare function existsSync(path: string): boolean;
|
|
|
25
25
|
declare function isDirectory(path: string): boolean;
|
|
26
26
|
/**
|
|
27
27
|
* Ensure a directory exists.
|
|
28
|
-
* If the path is not a directory, we will try to create it.
|
|
29
|
-
* If the path is a file, we will create the parent directory.
|
|
30
28
|
* @param dirPath - The path to ensure
|
|
31
29
|
* @returns `true` if the directory is created, `false` otherwise
|
|
32
30
|
*/
|
|
@@ -69,4 +67,13 @@ declare const highlight: {
|
|
|
69
67
|
reset: ansis0.Ansis;
|
|
70
68
|
};
|
|
71
69
|
//#endregion
|
|
72
|
-
|
|
70
|
+
//#region src/stringify.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* Stringify an object to a JSON string with functions support.
|
|
73
|
+
*
|
|
74
|
+
* @param obj - The object to stringify.
|
|
75
|
+
* @returns The JSON string.
|
|
76
|
+
*/
|
|
77
|
+
declare function stringify(obj: any): string;
|
|
78
|
+
//#endregion
|
|
79
|
+
export { fs_d_exports as fs, highlight, stringify, upsertUserRc };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { t as __export } from "./chunk-Bp6m_JJh.js";
|
|
2
2
|
import { readUser, updateUser, writeUser } from "rc9";
|
|
3
3
|
import { constants, copyFileSync, lstatSync, mkdirSync, promises, renameSync, unlinkSync } from "node:fs";
|
|
4
|
-
import { dirname } from "node:path";
|
|
5
4
|
import consola from "consola";
|
|
6
5
|
import { bold, cyan, green, magenta, red, reset } from "ansis";
|
|
7
6
|
|
|
@@ -69,13 +68,10 @@ function isDirectory(path) {
|
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
71
70
|
* Ensure a directory exists.
|
|
72
|
-
* If the path is not a directory, we will try to create it.
|
|
73
|
-
* If the path is a file, we will create the parent directory.
|
|
74
71
|
* @param dirPath - The path to ensure
|
|
75
72
|
* @returns `true` if the directory is created, `false` otherwise
|
|
76
73
|
*/
|
|
77
74
|
function ensureDir(dirPath) {
|
|
78
|
-
if (!isDirectory(dirPath)) dirPath = dirname(dirPath);
|
|
79
75
|
if (!existsSync(dirPath)) {
|
|
80
76
|
mkdirSync(dirPath, { recursive: true });
|
|
81
77
|
return true;
|
|
@@ -154,4 +150,20 @@ function removeSymlink(targetPath) {
|
|
|
154
150
|
}
|
|
155
151
|
|
|
156
152
|
//#endregion
|
|
157
|
-
|
|
153
|
+
//#region src/stringify.ts
|
|
154
|
+
function replacer(key, value) {
|
|
155
|
+
if (typeof value === "function") return `${value.toString()}`.replace(/\s+/g, " ").replace(/"/g, "'");
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Stringify an object to a JSON string with functions support.
|
|
160
|
+
*
|
|
161
|
+
* @param obj - The object to stringify.
|
|
162
|
+
* @returns The JSON string.
|
|
163
|
+
*/
|
|
164
|
+
function stringify(obj) {
|
|
165
|
+
return JSON.stringify(obj, replacer, 2);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
export { fs_exports as fs, highlight, stringify, upsertUserRc };
|