@gesslar/toolkit 3.32.0 → 3.33.1
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
package/src/browser/lib/Valid.js
CHANGED
|
@@ -23,8 +23,7 @@ export default class Valid {
|
|
|
23
23
|
static type(value, type, options) {
|
|
24
24
|
Valid.assert(
|
|
25
25
|
Data.isType(value, type, options),
|
|
26
|
-
`Invalid type. Expected ${type}, got ${
|
|
27
|
-
1,
|
|
26
|
+
`Invalid type. Expected ${type}, got ${Data.typeOf(value)}`
|
|
28
27
|
)
|
|
29
28
|
}
|
|
30
29
|
|
|
@@ -470,6 +470,88 @@ export default class FileObject extends FS {
|
|
|
470
470
|
return await import(filePath)
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
+
/**
|
|
474
|
+
* Copies the file to a new location and returns a new FileObject for the copy.
|
|
475
|
+
* Performs a byte-for-byte copy of the file contents.
|
|
476
|
+
*
|
|
477
|
+
* @param {string} destination - The destination file path
|
|
478
|
+
* @returns {Promise<FileObject>} A new FileObject representing the copied file
|
|
479
|
+
* @throws {Sass} If the source file does not exist
|
|
480
|
+
* @throws {Sass} If the copy operation fails
|
|
481
|
+
* @example
|
|
482
|
+
* const file = new FileObject('./image.png')
|
|
483
|
+
* const copied = await file.copy('./backup/image.png')
|
|
484
|
+
* console.log(copied.path) // /absolute/path/to/backup/image.png
|
|
485
|
+
*/
|
|
486
|
+
async copy(destination) {
|
|
487
|
+
Valid.type(destination, "String", {allowEmpty: false})
|
|
488
|
+
|
|
489
|
+
const filePath = this.path
|
|
490
|
+
|
|
491
|
+
if(!(await this.exists))
|
|
492
|
+
throw Sass.new(`No such file '${filePath}'`)
|
|
493
|
+
|
|
494
|
+
const destFile = new FileObject(destination)
|
|
495
|
+
|
|
496
|
+
try {
|
|
497
|
+
await fs.copyFile(filePath, destFile.path)
|
|
498
|
+
} catch(error) {
|
|
499
|
+
throw Sass.new(`Failed to copy file to '${destFile.path}'`, error)
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return destFile
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Moves the file to a new location and returns a new FileObject for the
|
|
507
|
+
* moved file. Uses rename when possible, falling back to copy and delete
|
|
508
|
+
* for cross-device moves.
|
|
509
|
+
*
|
|
510
|
+
* @param {string} destination - The destination file path
|
|
511
|
+
* @returns {Promise<FileObject>} A new FileObject representing the moved file
|
|
512
|
+
* @throws {Sass} If the source file does not exist
|
|
513
|
+
* @throws {Sass} If the move operation fails
|
|
514
|
+
* @example
|
|
515
|
+
* const file = new FileObject('./data.json')
|
|
516
|
+
* const moved = await file.move('./archive/data.json')
|
|
517
|
+
* console.log(moved.path) // /absolute/path/to/archive/data.json
|
|
518
|
+
*/
|
|
519
|
+
async move(destination) {
|
|
520
|
+
Valid.type(destination, "String", {allowEmpty: false})
|
|
521
|
+
|
|
522
|
+
const filePath = this.path
|
|
523
|
+
|
|
524
|
+
if(!(await this.exists))
|
|
525
|
+
throw Sass.new(`No such file '${filePath}'`)
|
|
526
|
+
|
|
527
|
+
const destFile = new FileObject(destination)
|
|
528
|
+
|
|
529
|
+
try {
|
|
530
|
+
await fs.rename(filePath, destFile.path)
|
|
531
|
+
} catch(error) {
|
|
532
|
+
if(error.code === "EXDEV") {
|
|
533
|
+
try {
|
|
534
|
+
const stat = await fs.lstat(filePath)
|
|
535
|
+
|
|
536
|
+
if(stat.isSymbolicLink()) {
|
|
537
|
+
const target = await fs.readlink(filePath)
|
|
538
|
+
await fs.symlink(target, destFile.path)
|
|
539
|
+
} else {
|
|
540
|
+
await fs.copyFile(filePath, destFile.path)
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
await fs.unlink(filePath)
|
|
544
|
+
} catch(fallbackError) {
|
|
545
|
+
throw Sass.new(`Failed to move file to '${destFile.path}'`, fallbackError)
|
|
546
|
+
}
|
|
547
|
+
} else {
|
|
548
|
+
throw Sass.new(`Failed to move file to '${destFile.path}'`, error)
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
return destFile
|
|
553
|
+
}
|
|
554
|
+
|
|
473
555
|
/**
|
|
474
556
|
* Deletes the file from the filesystem.
|
|
475
557
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Valid.d.ts","sourceRoot":"","sources":["../../../src/browser/lib/Valid.js"],"names":[],"mappings":"AAWA;;GAEG;AACH;IACE;;;;;;OAMG;IACH,mBAJW,OAAO,QACP,MAAM,YACN,MAAM,
|
|
1
|
+
{"version":3,"file":"Valid.d.ts","sourceRoot":"","sources":["../../../src/browser/lib/Valid.js"],"names":[],"mappings":"AAWA;;GAEG;AACH;IACE;;;;;;OAMG;IACH,mBAJW,OAAO,QACP,MAAM,YACN,MAAM,QAOhB;IAED;;;;;;;;OAQG;IACH,yBANW,OAAO,WACP,MAAM,QAEN,MAAM,QAkBhB;IAED,+CAAmE;IAEnE;;;;;;OAMG;IACH,0CAHW,KAAK,CAAC,MAAM,CAAC,QAYvB;CACF"}
|
|
@@ -209,6 +209,35 @@ export default class FileObject extends FS {
|
|
|
209
209
|
* @returns {Promise<object>} The file contents as a module.
|
|
210
210
|
*/
|
|
211
211
|
import(): Promise<object>;
|
|
212
|
+
/**
|
|
213
|
+
* Copies the file to a new location and returns a new FileObject for the copy.
|
|
214
|
+
* Performs a byte-for-byte copy of the file contents.
|
|
215
|
+
*
|
|
216
|
+
* @param {string} destination - The destination file path
|
|
217
|
+
* @returns {Promise<FileObject>} A new FileObject representing the copied file
|
|
218
|
+
* @throws {Sass} If the source file does not exist
|
|
219
|
+
* @throws {Sass} If the copy operation fails
|
|
220
|
+
* @example
|
|
221
|
+
* const file = new FileObject('./image.png')
|
|
222
|
+
* const copied = await file.copy('./backup/image.png')
|
|
223
|
+
* console.log(copied.path) // /absolute/path/to/backup/image.png
|
|
224
|
+
*/
|
|
225
|
+
copy(destination: string): Promise<FileObject>;
|
|
226
|
+
/**
|
|
227
|
+
* Moves the file to a new location and returns a new FileObject for the
|
|
228
|
+
* moved file. Uses rename when possible, falling back to copy and delete
|
|
229
|
+
* for cross-device moves.
|
|
230
|
+
*
|
|
231
|
+
* @param {string} destination - The destination file path
|
|
232
|
+
* @returns {Promise<FileObject>} A new FileObject representing the moved file
|
|
233
|
+
* @throws {Sass} If the source file does not exist
|
|
234
|
+
* @throws {Sass} If the move operation fails
|
|
235
|
+
* @example
|
|
236
|
+
* const file = new FileObject('./data.json')
|
|
237
|
+
* const moved = await file.move('./archive/data.json')
|
|
238
|
+
* console.log(moved.path) // /absolute/path/to/archive/data.json
|
|
239
|
+
*/
|
|
240
|
+
move(destination: string): Promise<FileObject>;
|
|
212
241
|
/**
|
|
213
242
|
* Deletes the file from the filesystem.
|
|
214
243
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;GAaG;AAEH;IACE;;;;;OAKG;IACH,yBAFU;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,KAAK,GAAG,OAAO,IAAI,CAAC,CAAA;KAAC,CAO1D;
|
|
1
|
+
{"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;GAaG;AAEH;IACE;;;;;OAKG;IACH,yBAFU;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,KAAK,GAAG,OAAO,IAAI,CAAC,CAAA;KAAC,CAO1D;IAghBF;;;;;;;;;;;OAWG;IACH,kBAPa,UAAU,CAsCtB;IAjiBD;;;;;OAKG;IACH,uBAHW,MAAM,WACN,eAAe,GAAC,MAAM,GAAC,IAAI,EA+DrC;IAWD;;;;OAIG;IACH,cAFa,OAAO,CAAC,OAAO,CAAC,CAI5B;IAED;;;;OAIG;IACH,g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