@io-arc/file-list

Get the file list.

Usage#

$ npm i @io-arc/file-list
index.ts
import { FileListObject } from '@io-arc/file-list'
const res = FileListObject('foo', 'js')
// -> Result: {abc: 'foo/abc.js', 'foo/bar/def': 'foo/bar/def.js'}

Functions#

FileListObject(dir, ext[, rootOnly])#

Return: {[key: string]: string}

Get a list of files as an object recursively by specifying the directory and extension. The key name of the object will be the file name.

Parameters

paramstypedefaultdescription
dirstring-Target directory name
extstring-Extension name
rootOnly (optional)booleanfalseOnly files directly under the specified directory

example

Directory
data/
โ”œ abc.js
โ”œ def.js
โ”œ ghi.json
โ”” foo/
โ”œ jkl.js
โ”” mno.json
import { FileListObject } from '@io-arc/file-list'
const res1 = FileListObject('data', 'js')
console.log(res1)
// -> { abc: 'data/abc.js', def: 'data/def.js', 'foo/jkl': 'data/foo/jkl.js' }
const res2 = FileListObject('data', 'json', true)
console.log(res2)
// -> { ghi: 'data/ghi.json' }