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

docs-snippet

v1.0.4

Published

[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)

Downloads

7

Readme

Contributor Covenant

The docs-snippet library is a way to convert a snippet of TypeScript code into the equivalent JavaScript code, with whitespace and comments preserved as much as possible. It also uses prettier to format both the JavaScript and TypeScript code to attempt to normalize them as much as possible while still preserving whitespace.

It also provides a way to specify regions and highlights inline in the code.

import Snippet from "docs-snippet";

const snippet = Snippet(`
  // #region first
  // This is a comment
  const x: number = 1;
  // #endregion

  // #region second
  /* This is a block comment */
  // #highlight:next
  const y = 2; // an inline comment

  // #highlight:start
  const z = 3;
  const a: number = x + y + z;
  // #highlight:end

  console.log(a);
  // #endregion
`);

const regionA = snippet.regions.a;

expect(regionA.ts.code).toBe("// This is a comment\nconst x: number = 1;\n");
expect(regionA.js.code).toBe("// This is a comment\nconst x = 1;\n");

const regionB = snippet.regions.b;

expect(regionB.ts.code).toBe(
  "/* This is a block comment */\n" +
    "const y = 2; // an inline comment\n" +
    "\n" +
    "const z = 3;\n" +
    "const a: number = x + y + z;\n" +
    "\n" +
    "console.log(a);\n"
);

expect(regionB.ts.highlights.map((h) => h.lines)).toEqual(["2", "4-5"]);

expect(regionB.js.code).toBe(
  "/* This is a block comment */\n" +
    "const y = 2; // an inline comment\n" +
    "\n" +
    "const z = 3;\n" +
    "const a = x + y + z;\n" +
    "\n" +
    "console.log(a);\n"
);

expect(regionB.js.highlights.map((h) => h.lines)).toEqual(["2", "4-5"]);