stc-file

Virtual file for stc

Usage no npm install needed!

<script type="module">
  import stcFile from 'https://cdn.skypack.dev/stc-file';
</script>

README

stc-file

Virtual File for stc

How to use

import File from 'stc-file';

let file = new File({
  cwd: '', //current work path
  base: '', //base name
  path: 'path/to/file', //file path
  stat: null //file stat
});

API

path

get or set file path.

file.path = 'xxx';
file.path; 

extname

get or set file extname.

file.extname; // html
file.extname = 'txt'; //

stat

get or set file stat.

let stat = file.stat;
file.stat = stat;

isFile()

let isFile = file.isFile();

isDirectory()

let isDirectory = file.isDirectory();

pipe(stream, opt)

pipe file stream to another stream.

file.pipe(stream, {
  end: true
});

isPath(filepath)

check file path

getContent(encoding)

get file content,

  • encoding default is null

setContent(content)

hasAst()

check file aleady have ast

getAst()

setAst(ast)

prop(name, value)

get or set other property for file