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

@sayjava/phake-cli

v1.1.0

Published

Effortlessly Generate Realistic Mock Data with Ease using Handlebars and Fakerjs

Downloads

5

Readme

Features

  • Utilize the power of declarative templates using Handlebars.
  • Seamlessly integrate with Faker.js for generating realistic and randomized data.
  • Enjoy the simplicity of a command-line interface for streamlined usage.
  • Incorporate the tool into your development process and easily version your templates.
  • Promote code reuse and maintainability by creating DRY (Don't Repeat Yourself) templates, allowing you to reuse template sections across multiple templates.
  • Leverage custom Handlebars helpers to simplify data creation and manipulation, further enhancing the flexibility and functionality of your templates.

Quick Start

Create a template file named sample.json.hbs with the following content

 {
    "id": {{faker 'number.int' 10}},
    "node_id": "{{faker 'string.alpha' 25}}",
    "name": "{{faker 'word.noun'}}",
    "language": "{{randomize 'javascript' 'ruby' 'golang' 'c++'}}",
    "forks_count": {{faker 'number.int' max=10000}},
    "size": {{faker 'number.float' max=10000 precision=0.2}},
    "default_branch": "{{randomize 'main' 'master'}}",
    "open_issues_count": {{faker 'number.int' max=50}},
    "is_template": {{randomize false true}},
    "description": "{{faker 'lorem.sentences' max=3}}",
    "topics": [
        {{#repeat 5}}
            "{{faker 'string.alpha' 5}}"
        {{/repeat}}
    ]
}

Run the phake-cli command to compile the template into user.json

npx @sayjava/phake-cli compile -t sample.json.hbs
{
  "id": 7,
  "node_id": "HSUWMxwXsVKxycdaVOiJFnlNe",
  "name": "factory",
  "language": "javascript",
  "forks_count": 4558,
  "size": 8800,
  "default_branch": "master",
  "open_issues_count": 9,
  "is_template": true,
  "description": "Aliquam sunt eveniet quam",
  "topics": [
    "UiqiJ",
    "GdyVl",
    "LUiDO",
    "QEHha",
    "Ksvjv"
  ]
}

Phake Compile

The Phake CLI uses Handlebars and FakerJS to generate sample data for development purposes. It allows you to define data templates using Handlebars syntax and generate realistic sample data based on those templates, incorporating fake data generated by FakerJS.

Installation

npm i -g @sayjava/phake-cli

CLI Options

| Flag | Default | Description | | -------------- | ------- | --------------------------------------- | | -t, --template | - | file/directory containing .hbs files | | -o, --output | cwd | The directory to write the output files |

File Naming

Improve the functionality of the phake CLI with the following enhancements:

  • The phake CLI now intelligently uses file extensions to name the output files that are written to the output directory.
  • If no file extension is supplied, the output file will still be created but without any file extension.
  • This flexible approach allows you to specify the desired file extension for the output, providing compatibility with various file formats and ensuring clarity in file naming.
  • You can now generate output files with the appropriate extensions, making it easier to identify and work with the generated files.
  • This enhancement adds versatility to the phake CLI, catering to a wider range of use cases and preferences.

Examples

| Input | Output | | --------------- | ----------- | | sample.json.hbs | sample.json | | sample.yaml.hbs | sample.yaml | | sample.hbs | sample |

Usage

phake compile -t name-of-template.hbs

Compile a folder containing .hbs files

phake -t dir/containing-hbs-files -o folder/to/write/output

Compile a single [name].hbs file

phake -t dir/containing/single.hbs -o folder/to/write/output

Compile a single [name].json.hbs file with an explicit file extension. This will create [name].json

phake -t dir/containing/single.json.hbs -o folder/to/write/output

DRY Templates with Handlebar's Partials

  • Enable easy reuse of template sections by naming them as [name].partial.hbs.
  • Partial files are not compiled individually but instead registered as Handlebar partials. This allows them to be referenced and included within other template files seamlessly.
  • By adopting this approach, you can efficiently organize and manage your templates, promoting modular and reusable code.
  • The registration of partials ensures that changes made to a partial file reflect automatically across all templates that reference it.
  • This method of partial registration enhances maintainability and reduces duplication of code within your project.

Example

{
  "title": "{{ faker "company.name" }}",
  "price": "{{ faker "commerce.price" min=100 max=200 dec=0 symbol='£' }}"
}

The partial can then be referenced from other template files

{
  "items": [
    {{#repeat 3}}
        {{> item }}
    {{/repeat}}
  ],
}

Template Helpers

phake ships with some handy helpers that eases data generation. All Handlebar Helpers are also supported.

| Helper | Description | Example | | --------- | ------------------------------------ | ----------------------------------------------------------- | | repeat | Repeat items | {{#repeat 5}} index-{{@index}} {{/repeat}} | | randomize | Randomize an array | {{randomize "german shepard" "golden retriever" "pug"}} | | setVar | Register a variable to be used later | {{#setVar 'myVar' 5 }} then accessed later as {{myVar}} |

Examples

See the examples folder for more advance use cases