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

justo-assert-fs

v0.3.3

Published

Assertion library for files and directories.

Downloads

12

Readme

Build Status

An assertion library for files.

Proudly made with ♥ in Valencia, Spain, EU.

Features:

  • Allow to assert files.
  • Allow to access the file content: text, JSON and YAML.
  • Allow to assert directories.

Install

npm install justo-assert-fs

Table of contents

  1. File assertions
  2. Directory assertions

File assertions

To assert files, we have to use the file() function as starting point:

file(path : string)
file(dir : string, file : string)

Once created the file object, we have to use the must property to assert.

Example:

const file = require("justo-assert-fs").file;

file("/my/dir", "file.txt").must.exist()

must.exist() and must.not.exist()

Checks whether the file exists:

must.exist()
must.exist(msg : string)

must.not.exist()
must.not.exist(msg : string)

must.contain() and must.not.contain()

Checks whether the file contains a text or several texts:

must.contain(txt : string)
must.contain(txt : string, msg : string)
must.contain(txts : string[])
must.contain(txts : string[], msg : string)

must.not.contain(txt : string)
must.not.contain(txt : string, msg : string)
must.not.contain(txt : string[])
must.not.contain(txt : string[], msg : string)

must.be.equal(), must.be.eq(), must.not.be.equal() and must.not.be.eq()

Checks whether the file content is equal to a given text:

must.be.eq(txt : string)
must.be.eq(txt : string, msg : string)

must.not.be.eq(txt : string)
must.not.be.eq(txt : string, msg : string)

Asserting JSON files

must.be.json() and must.not.be.json()

Checks whether the file content is a JSON object:

must.be.json()
must.be.json(msg : string)

must.not.be.json()
must.not.be.json(msg : string)

json property

The file object contains a json property for returning the content as an object. We can use, for example, justo-assert to check the content:

file("myfile.json").json.must.be.eq({...});

Asserting YAML files

must.be.yaml() and must.not.be.yaml()

Checks whether the file is a YAML file:

must.be.yaml()
must.be.yaml(msg : string)

must.not.be.yaml()
must.not.be.yaml(msg : string)

yaml property

Similarly to json, the file object has a yaml property for returning the content as an object:

file("myfile.yml").yaml.must.be.eq({...});

Asserting text files

text property

Similarly to json and yaml, we also have the text property:

file("myfile.txt").text.must.be.eq({...});

Directory assertions

To assert directories, we have to use the dir() function as starting point:

dir(path : string)
dir(parent : string, name : string)

Once created the direcory object, we have to use the must property to assert.

Example:

const dir = require("justo-assert-fs").dir;

dir("/my/dir", "subdir").must.exist()

must.exist() and must.not.exist()

Checks whether the directory exists:

must.exist()
must.exist(msg : string)

must.not.exist()
must.not.exist(msg : string)

must.have() and must.not.have()

Checks whether the directory contains a specified entry set (file, directories...):

must.have(entry : string)
must.have(entry : string, msg : string)
must.have(entries : string[])
must.have(entries : string[], msg : string)

must.not.have(entry : string)
must.not.have(entry : string, msg : string)
must.not.have(entries : string[])
must.not.have(entries : string[], msg : string);