1
1
import fs from 'node:fs' ;
2
- import { dirname , extname } from 'node:path' ;
3
- import { fileURLToPath } from 'node:url' ;
2
+ import nodePath from 'node:path' ;
3
+ import url from 'node:url' ;
4
4
5
5
import { Mask , Image } from '..' ;
6
6
@@ -74,14 +74,14 @@ export async function write(
74
74
options ?: WriteOptionsPng | WriteOptionsJpeg | WriteOptions ,
75
75
) : Promise < void > {
76
76
if ( typeof path !== 'string' ) {
77
- path = fileURLToPath ( path ) ;
77
+ path = url . fileURLToPath ( path ) ;
78
78
}
79
79
if ( image instanceof Mask ) {
80
80
image = image . convertColor ( 'GREY' ) ;
81
81
}
82
82
const toWrite = getDataToWrite ( path , image , options ) ;
83
83
if ( options ?. recursive ) {
84
- const dir = dirname ( path ) ;
84
+ const dir = nodePath . dirname ( path ) ;
85
85
await fs . promises . mkdir ( dir , { recursive : true } ) ;
86
86
}
87
87
await fs . promises . writeFile ( path , toWrite ) ;
@@ -100,14 +100,14 @@ export function writeSync(
100
100
options ?: WriteOptionsPng | WriteOptionsJpeg | WriteOptions ,
101
101
) : void {
102
102
if ( typeof path !== 'string' ) {
103
- path = fileURLToPath ( path ) ;
103
+ path = url . fileURLToPath ( path ) ;
104
104
}
105
105
if ( image instanceof Mask ) {
106
106
image = image . convertColor ( 'GREY' ) ;
107
107
}
108
108
const toWrite = getDataToWrite ( path , image , options ) ;
109
109
if ( options ?. recursive ) {
110
- const dir = dirname ( path ) ;
110
+ const dir = nodePath . dirname ( path ) ;
111
111
fs . mkdirSync ( dir , { recursive : true } ) ;
112
112
}
113
113
fs . writeFileSync ( path , toWrite ) ;
@@ -128,7 +128,7 @@ function getDataToWrite(
128
128
) : Uint8Array {
129
129
let format : ImageFormat ;
130
130
if ( ! options || ! ( 'format' in options ) ) {
131
- const extension = extname ( destinationPath ) . slice ( 1 ) . toLowerCase ( ) ;
131
+ const extension = nodePath . extname ( destinationPath ) . slice ( 1 ) . toLowerCase ( ) ;
132
132
if ( extension === 'png' ) {
133
133
format = 'png' ;
134
134
return encode ( image , { format } ) ;
0 commit comments