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

project-snippets

v0.4.0

Published

Keep code snippets directly in your project repository and let anyone create files easily and quickly.

Downloads

11

Readme

Project Snippets

Keep code snippets directly in your project repository and let anyone create files easily and quickly.

Quick start and how it works

Installation

First install package:

yarn add --dev project-snippets

# or npm

npm install --save-dev project-snippets

Now you have available snippet command, let's use this in package.json as create script:

{
    "scripts": {
        "create": "snippet create"
    }
}

You can run this by typing yarn run create or npm run create, but first you need .snippets directory with your code templates.

Snippets directory

For example you like to make a snippet for components in /src/components/*.js, then .snippets directory structure should look like this:

.snippets/
    src/
        components/
            MySimpleComponent.snippet/    ← Snippet name, this dir will be omitted
                (SomeName).js.tpl         ← Snippet files or even directories
                (someName).css.tpl        ← .tpl extension is important!

Now after running the create command, you will see list for your snippets. If you select MySimpleComponent and then enter the name eg. circle button it will create a file:

src/
    components/
        …
        CircleButton.js
        circleButton.css
        …

Let's look inside the files.

Templates

Inside the files will we use ejs templates:

(SomeName).js.tpl:

import '<%= someName %>.css'

export function <%= SomeName %>() {
    // ...
}

And similarly for (someName).css.tpl.

.<%= someName %> {
    /* ... */
}

Finally that's all, now you can run this command again and you will receive ready to use CircleButton.js and circleButton.css files:

import 'circleButton.css'

export function CircleButton() {
    // ...
}
.circleButton {
    /* ... */
}

CLI options

  • --dry-run - show the contents of files without creating them

Variables

The following variables are now available:

  • camelCase: someName
  • pascalCase: SomeName
  • snakeCase: some_name
  • paramCase: some-name
  • constantCase: SOME_NAME

Custom variables

If you need more options for your snippet you can create the options.json file in snippet directory. (And remember: empty file = no file)

Example .snippets/src/components/Component.snippet/options.json:

[
    {
        "type": "confirm",
        "name": "styles",
        "message": "With styles?"
    },
    {
        "type": "confirm",
        "name": "tests",
        "message": "With unit tests?"
    }
]

Roadmap

  • [x] Simple snippet generator
  • [x] --dry-run option
  • [x] Custom variables in snippets
  • [ ] Handlebars templates support
  • [ ] init command to example .snippet and script in package.json
  • [ ] Plugins:
    • [ ] Atom
    • [ ] Visual Studio Code
    • [ ] Sublime Text
    • [ ] WebStorm
  • [ ] generate command to create snippets from shared resources