@dnax/core 0.45.3 → 0.45.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/index.ts +54 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.45.3",
3
+ "version": "0.45.5",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/utils/index.ts CHANGED
@@ -385,6 +385,58 @@ const password = {
385
385
  };
386
386
 
387
387
  const file = {
388
+ cp: async (
389
+ src: string,
390
+ des: string,
391
+ options: {
392
+ force?: boolean;
393
+ } = { force: false }
394
+ ): Promise<{
395
+ size: number;
396
+ type: string;
397
+ lastModified: Date;
398
+ original_name: string | undefined;
399
+ name: string | undefined;
400
+ }> => {
401
+ return new Promise(async (resolve, reject) => {
402
+ try {
403
+ if (!(await fs.pathExists(des)) && !options?.force) {
404
+ reject("Already exist in destination");
405
+ }
406
+ await fs.copyFile(src, des);
407
+ let file = await Bun.file(des);
408
+ resolve({
409
+ original_name: file.name,
410
+ name: file.name,
411
+ lastModified: moment.unix(file.lastModified).toDate(),
412
+ size: file.size,
413
+ type: file.type,
414
+ });
415
+ } catch (err: any) {
416
+ reject(err?.message);
417
+ }
418
+ });
419
+ },
420
+ mv: async (
421
+ source: string,
422
+ destination: string,
423
+ options: {
424
+ overwrite?: boolean;
425
+ } = {
426
+ overwrite: false,
427
+ }
428
+ ) => {
429
+ return new Promise(async (resolve, reject) => {
430
+ try {
431
+ await fs.move(source, destination, {
432
+ overwrite: options?.overwrite,
433
+ });
434
+ resolve(true);
435
+ } catch (err: any) {
436
+ reject(err?.message);
437
+ }
438
+ });
439
+ },
388
440
  exist: async (path: string): Promise<boolean> => {
389
441
  return new Promise(async (resolve, reject) => {
390
442
  try {
@@ -402,6 +454,7 @@ const file = {
402
454
  size: number;
403
455
  type: string;
404
456
  lastModified: Date;
457
+ original_name: string | undefined;
405
458
  name: string | undefined;
406
459
  }> => {
407
460
  // save to disk
@@ -412,6 +465,7 @@ const file = {
412
465
  });
413
466
  let file = await Bun.file(path);
414
467
  resolve({
468
+ original_name: file.name,
415
469
  name: file.name,
416
470
  lastModified: moment.unix(file.lastModified).toDate(),
417
471
  size: file.size,