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

sscg

v1.0.0

Published

The super simple code generator

Downloads

166

Readme

sscg

The Super Simple Code Generator.

This package prioritizes stability with minimal version updates. Dependencies are regularly updated and bugs are fixed, but new features are not added and existing ones are not changed. This approach results in fewer version bumps, keeping the package simple and its behavior consistent.

Installation

$ npm install --save-dev sscg

Getting started

1. Create base directory

Default base directory is ./templates.

$ mkdir templates

2. Create your first template

Now, let's create a template.

$ mkdir templates/sample

The name of directory under the templates directory (here is sample) is treated as template name.

You can create multiple tpl files in the template directory.

$ touch templates/sample/{{kebabCase[singular[t]]}}.ts.tpl
$ mkdir templates/sample/some-dir
$ touch templates/sample/some-dir/{{kebabCase[plural[t]]}}.ts.tpl

sscg can embed string into the file name by evaluating codes in {{}}, and you can use [] instead of () for calling function in file names.

Then, let's edit your tpl files.

templates/sample/{{kebabCase[singular[t]]}}.ts.tpl:

export type {{pascalCase(singular(t))}} = {};

templates/sample/some-dir/{{kebabCase[plural[t]]}}.ts.tpl:

import type { {{pascalCase(singular(t))}} } from "../{{kebabCase(singular(t))}}";

export type {{pascalCase(plural(t))}} = Array<{{pascalCase(singular(t))}}>;

sscg can embed string into tpl files by evaluating codes in {{}}.

3. Generate codes from the your template

You can generate code with the following command.

$ sscg sample -r sample_record -o outputs
Generate from 'templates/sample'...

outputs/sample-record.ts
outputs/some-dir/sample-records.ts

Done in 11ms

The -r option is replacement, and it becomes t in {{}}.

outputs/sample-record.ts:

export type SampleRecord = {};

outputs/some-dir/sample-records.ts:

import type { SampleRecord } from "../sample-record";

export type SampleRecords = Array<SampleRecord>;

Supported variables

| | kind | desc | |----------------|----------|-----------------------------------------| | t | value | A string from the -r option | | plural | function | Pluralize a string | | singular | function | Singularize a string | | camelCase | function | Transform a string like sampleRecord | | constantCase | function | Transform a string like SAMPLE_RECORD | | kebabCase | function | Transform a string like sample-record | | pascalCase | function | Transform a string like SampleRecord | | snakeCase | function | Transform a string like sample_record |

Usage

The super simple code generator

Usage:
  $ sscg <name> [options]

Options:
  -r, --replacement <text>  The string that replaces tokens in templates
  -o, --out <dir>           The output directory where generated codes are located
  -d, --dir <dir>           The directory where templates are located (default: ./templates)

Example:
  $ sscg model -r user -o ./models