Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1.73 KB

File metadata and controls

37 lines (27 loc) · 1.73 KB

File API

The “file API” is provided by the File class. It effectively binds a file path to the current Context object, so you can pass it around more easily.

While the File class is provided by the jumpgen package, you may want to use the context-specific File class instead, which has the context injected for you. In particular, it's really handy if you prefer to destructure the context object (in which case, you won't have a reference to the entire context anymore).

import { jumpgen, File } from 'jumpgen'

// The “hard” way to create a File object:
const myGenerator = jumpgen('name', context => {
  const file = new File('path/to/file.txt', context)
})

// The simpler way to create a File object:
const otherGenerator = jumpgen('other', ({ File }) => {
  const file = new File('path/to/file.txt')
})

File instance

  • Properties

    • path: The file path, relative to the root directory.
    • name: The file's base name.
    • absolutePath: The file path prefixed with the root directory.
  • Methods

    • exists(): Whether the file exists on the filesystem. Read more
    • isFile(): Whether the file exists and is a regular file. Read more
    • isDirectory(): Whether the file exists and is a directory. Read more
    • isSymlink(): Whether the file exists and is a symbolic link. Read more
    • read(options?): Read the file's contents. Read more
    • tryRead(options?): Read the file's contents, returning null if the file does not exist. Read more
    • write(data): Write data to the file. Read more