npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

makestatic-filewrap

v1.0.35

Published

File wrapper library

Downloads

11

Readme

Filewrap

File object wrapper

Wraps a file path as a complex object with many useful properties and functions.



Install

yarn add makestatic-filewrap

API

File

Custom file wrapper.

To create a new file you should pass it the file name and a root directory the file is relative to:

const file = new File({ name: 'src/file.txt', root: 'src' })

If you already have the file content and know where it should be written you can set the output and content properties:

const file = new File({
  name: 'src/file.txt',
  root: 'src',
  output: 'public/out.txt',
  content: 'File content' })

File

new File(options)

Create a new File instance.

You can pass any writable properties in the options object and they will be set on this file.

  • options file options.
Options
  • name String the file name.
  • root String the directory the file is relative to.
  • output String the output file path to write to.
  • content Buffer|String the file output content.
  • buffer Buffer|String the file source content.
  • extension String an output file extension.
  • seal Function a function used to update the file content.

name

String name

Raw input file name, may be absolute or relative.

basename

readonly String basename

The basename for the input file assigned when the name is set.

path

readonly String path

File path relative to the root directory.

If an output path is specified it is used otherwise the raw input file name is used.

This property evaluates the path using the current output or file name so should be used only when necessary but will always reflect the current state of the file not the instantiation state.

stat

Object stat

A stat object associated with the source file.

buffer

Object buffer

A buffer containing the source file content.

output

String output

The output file path.

content

Buffer content

The content to write to disc.

transient

Boolean transient

Mark a file as transient.

Files marked as transient should never be written to disc.

seal

Function seal

A function used to seal the file contents.

Typically used when parsing a file to an abstract syntax tree and performing transformations on the tree.

root

String root

The directory path that this file is relative to.

hash

Object hash

An object used to store checksums.

extension

String extension

Extension used to rename the file extension when the output path is set. It should not contain a period.

ast

readonly Object ast

Map of abstract syntax tree objects associated with this file.

.getDetails

File.prototype.getDetails(name)

Get an object with name and file extension properties.

When no name argument is given the basename of this file is used.

Returns object map containing name and extension properties.

  • name String the name of the file.

.write

File.prototype.write(resolve, reject)

Write this file to disc using the output path and content buffer.

If an error occurs it is passed to the reject function otherwise the resolve function is called.

  • resolve Function called when the file is written.
  • reject Function called if the file write errors.
Throws
  • Error if this file has already been written to disc.
  • Error if the file write fails.

.update

File.prototype.update()

Update the output content associated with this file.

If a seal function has been assigned it is called and should return the transformed content.

Returns buffer updated file content.

.checksum

File.prototype.checksum(val, algorithm)

Calculate a checksum for a value.

Returns string hex encoded checksum.

  • val String|Buffer the value for the checksum.
  • algorithm String=sha512 the checksum algorithm.

.source

File.prototype.source()

Webpack asset compatible function to access the output content buffer.

Returns buffer file output content.

.size

File.prototype.size()

Webpack asset compatible function to access the output content buffer size.

Returns number of bytes in the output content buffer.

License

MIT


Created by mkdoc on March 12, 2017