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

metalsmith-assert

v1.0.2

Published

Metalsmith assert plugin.

Downloads

3

Readme

Build Status License NPM Downloads Known Vulnerabilities Coverage Status

metalsmith-assert

A Metalsmith plugin for testing the file objects with Node's assert module.

Usage

Install as usual, npm install metalsmith-assert.

Javascript: use(metalsmith-assert(assertions, options))

CLI: You'll lose a few options since it can't support functions.

By default, metalsmith-assert will console.log all AssertionErrors and a summary line. It then calls done(error) with the last AssertionError (if any) or null if all is well.

Assertions

assertions should be an object containing objects of the following format:

testname : {  // used for the message
  assert:     // which method of assert to call, default -> "ok".  See below.
  actual:     // if a string, the use fileData[actual],
              // special case: if '.', use fileData.contents.toString()
              // else call actual(fileData, filePath, metalsmith)
  expected:   // if a string use it
              // else call expected(fileData, filePath, metalsmith)
              // note: this field is ignored if assert is "ok"
}
Legal values for assert method are all methods from assert that take "actual" as the first argument.
  • deepEqual(actual, expected, ...)
  • deepStrictEqual(actual, expected, ...)
  • equal(actual, expected, ...)
  • notDeepEqual(actual, expected, ...)
  • notDeepStrictEqual(actual, expected, ...)
  • notEqual(actual, expected, ...)
  • notStrictEqual(actual, expected, ...)
  • ok(actual, ...) (the default method)
  • strictEqual(actual, expected, ...)

Be precise in your spelling and capitalization. You can also use an array of objects, in which case the testname will be the less informative "test N".

Options (all default to null/false)

options.quiet Don't log individual failures, nor the summary of passed/failed.

options.continueBuildOnError Always call done(null) even if there was a failure.

  • If you enable both quiet and continueBuildOnError this module is useless. :-)

options.disable a quick way to turn metalsmith-assert off - it will immediately call done().

options.fileFilter determines which files will be included

  • if missing, include all files.
  • if a string or Regex, only include matching filePaths.
  • if a user-provided-function, include the file when filter(filePath, data, metalsmith) returns true.
    e.g. If you want to use multimatch, pass something like function(filePath) { return multimatch([filePath], ["blogs/**", ...])[0] };

Examples

To verify that every file has a title, has a tag === "vacation", and the img is a svg file

.use(metalsmith-assert({
      "title exists" : { actual: "title"},
      "tag === vacation" : { assert: "equal", actual: "tag", expected: "vacation" },
      "image is svg" : { actual: function(data) { return /\.svg$/.test(data.img); }
    } ) )

Notes, Todos, and Caveats

Be precise in your spelling and capitalization!