1.1.10 • Published 4 years ago
lookfs v1.1.10
Contents
- Example
- Reference - root - fs(... path) - class LookFS - lookfs.ls - lookfs.all - lookfs.flat(depth) - lookfs.up(height) - lookfs.down(depth) - lookfs.size() - lookfs.fsize() - lookfs.height() - lookfs.depth() - lookfs.print() - lookfs.remove() - lookfs.chmod(mode) - lookfs.chown(owner, group) - lookfs.touch(atime, mtime) - class List - NodeList.from(asyncIterator) - NodeList.of(... nodes) - NodeList.concat(... lists) - NodeList.clone(list) - list.toArray() - list.map(func) - list.reduce(aggrFunc, initValue) - list.empty() - list.count() - list.some(cond) - list.every(cond) - list.find(cond) - list.parents - list.roots - list.filter(cond) - list.dirs - list.files - list.hidden - list.visible - list.ext(... exts) - list.access(mode) - list.loop - list.limit(count) - list.skip(offset) - class DirList - dirlist.get(... path) - class FileList - class Node - node.root - node.parent - node.name - node.ext - node.path - node.absPath - node.type - node.isRoot - node.isDir - node.isFile - node.isLink - node.isFIFO - node.isSocket - node.isBlock - node.isChar - node.isDot - node.toString() - node.toList() - node.access(mode) - node.isAccess(mode) - node.stat() - class Dir - class Root - class File - class Link - class BlockDevice - class CharacterDevice - class FIFO - class Socket - class Unknown
Example
import {fs, root} from 'lookfs'
root // absolute root dir
const myRoot = fs('/path/to/root'); // local root
(async function(){
await myRoot.ls.print(); // print children
await myRoot.ls.ls.print(); // print children of children
await myRoot.flat(2).print(); // print children and children of children
await myRoot.all.print(); // print all children and root
await myRoot.ls.all.print(); // print all children
await myRoot.all.dirs.print(); // print all children dirs and root
await myRoot.all.files.limit(100).print(); // print first 100 children files
// print children of images in /path/to/root/images dir
const myRoot.get('images').ls.ext('jpeg', 'jpg', 'png', 'gif').print();
// search files by name
const myRoot.all.search(/^zuzuka/i).print();
console.log(await myRoot.size()); // calc total size of myRoot
console.log(await myRoot.depth()); // calc max depth of children
console.log(await myRoot.ls.all.count()); // count all children of myRoot
for await(const node of myRoot.all.files){
console.log(`${node.name} ${await node.fsize()}`);
// print all filenames of regylar file and formated size
}
// get file
await file = myRoot.get('images/image.jpg');
console.log(file.name); // print "image.jpg"
console.log(file.path); // print "images/image.jpg"
console.log(file.absPath); // print "/path/to/root/images/image.jpg"
console.log(file.parent); // print /path/to/root/image dir
console.log(file.root); // print /path/to/root dir
console.log(file.height()); // print 2 - level of file
console.log(await file.stat()); // stat
console.log(await file.size()); // size
await myRoot.chmod(0x777); // chmod myRoot
await myRoot.all.dirs.chown(1000, 1000); // chown myRoot and all files
await myRoot.ls.hidden.remove(); // unlink all hidden files in myRoot
await myRoot.remove(); // remove dir myRoot with all files
})()
Reference
root
Absolute root dir
- return Root
fs(... path)
Reletive root dir
- return Root
class LookFS
lookfs.ls
Children iterator
- return List
lookfs.all
Self and all descendants iterator
- return List
lookfs.flat(depth)
- return List
lookfs.up(height)
- return List
lookfs.down(depth)
- return List
lookfs.size()
- return Integer
lookfs.fsize()
- return String
lookfs.height()
- return Integer
lookfs.depth()
- return Integer
lookfs.print()
lookfs.remove()
lookfs.chmod(mode)
lookfs.chown(owner, group)
lookfs.touch(atime, mtime)
class List
- extends LookFS
NodeList.from(asyncIterator)
- return List
NodeList.of(... nodes)
- return List
NodeList.concat(... lists)
- return List
NodeList.clone(list)
- return List
list.toArray()
- return Promise of Array
list.map(func)
- return Promise of Array
list.reduce(aggrFunc, initValue)
- return any value
list.empty()
- return Boolean
list.count()
- return Integer
list.some(cond)
- return Boolean
list.every(cond)
- return Boolean
list.find(cond)
- return Node
list.parents
- return List
list.roots
- return List
list.filter(cond)
- return List
list.dirs
- return DirList
list.files
- return FileList
list.hidden
- return List
list.visible
- return List
list.ext(... exts)
- return List
list.access(mode)
- return List
list.loop
- return List
list.limit(count)
- return List
list.skip(offset)
- return List
class DirList
- extends List
dirlist.get(... path)
- return List
class FileList
- extends List
class Node
- extends LookFS
node.root
- return Root
node.parent
Name of node
node.name
Filename of node
- return String
node.ext
File extends of node
- return String
node.path
Reletive path of node
- return String
node.absPath
- return String
node.type
- return Integer
node.isRoot
- return Boolean
node.isDir
- return Boolean
node.isFile
- return Boolean
node.isLink
- return Boolean
node.isFIFO
- return Boolean
node.isSocket
- return Boolean
node.isBlock
- return Boolean
node.isChar
- return Boolean
node.isDot
- return Boolean
node.toString()
- return String
node.toList()
- return List
node.access(mode)
node.isAccess(mode)
- return Boolean
node.stat()
- return Stat
class Dir
- extends Node
dir.get(... path)
- return Node
class Root
- extends Dir
class File
- extends Node
class Link
- extends Node
class BlockDevice
- extends Node
class CharacterDevice
- extends Node
class FIFO
- extends Node
class Socket
- extends Node
class Unknown
- extends Node