@@ -3,13 +3,13 @@ import path from 'path';
3
3
4
4
const DEFAULT_IMAGE_DIR = path . join ( __dirname , '..' , 'img' ) ;
5
5
6
- export const dirFor = ( type , imageDir ) => {
6
+ export const dirFor = ( type , imageDir = DEFAULT_IMAGE_DIR ) => {
7
7
if ( type ) return path . join ( imageDir , type ) ;
8
8
else return imageDir ;
9
9
} ;
10
10
11
- export const allNames = ( type ) => {
12
- return fs . readdirSync ( dirFor ( type ) ) . filter ( function ( imageFileName ) {
11
+ export const allNames = ( type , imageDir = DEFAULT_IMAGE_DIR ) => {
12
+ return fs . readdirSync ( dirFor ( type , imageDir ) ) . filter ( function ( imageFileName ) {
13
13
return imageFileName . match ( / \. p n g / ) ;
14
14
} ) . map ( function ( imageFileName ) {
15
15
return imageFileName . replace ( / \. p n g / , '' ) ;
@@ -19,11 +19,11 @@ export const allNames = (type) => {
19
19
export const allPaths = ( type , imageDir = DEFAULT_IMAGE_DIR ) => {
20
20
var dir ;
21
21
dir = dirFor ( type , imageDir ) ;
22
- return allNames ( type ) . map ( function ( name ) {
22
+ return allNames ( type , imageDir ) . map ( function ( name ) {
23
23
return path . join ( dir , name + '.png' ) ;
24
24
} ) ;
25
25
} ;
26
26
27
- export const pathFor = ( type , fileName ) => {
28
- return path . join ( dirFor ( type ) , fileName + '.png' ) ;
27
+ export const pathFor = ( type , fileName , imageDir = DEFAULT_IMAGE_DIR ) => {
28
+ return path . join ( dirFor ( type , imageDir ) , fileName + '.png' ) ;
29
29
} ;
0 commit comments