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

lord-fakealot

v1.1.3

Published

Generate Mockdata for your app

Downloads

20

Readme

lord-fakealot

Codacy Badge

lord-fakealot is a utility to generate mocked data based on typescript interfaces. It loads all interfaces from a given directory and can either expose an HTTP api or generate json files with mocked data in it

Install

npm i -g lord-fakealot This will then expose fakealot as a CLI entrypoint for this app

Data population

Under the hood, lord-fakealot uses faker. You can use any faker API Method in your annotations by writing @faker <api method>.

Example

export interface FakerInterface {
    /**
     * @faker lorem.word
     */
    word: string;
    
    /**
     * @faker lorem.paragraphs
     */
    paragraphs: string;
    
    /**
     * @faker finance.amount
     */
    finance: string;
    
}

Commands

|command | description | |---|---| |help | prints the help text| |api| exposes an HTTP API on a given port| |file| generate a file containing all populated interfaces| |files| generating a folder, containing JSON a json file for each interface |

help

Prints the help info to the CLI

fakealot -h

files

This commands create a jsonfile for every interface found in the dir directory. The name of each file is the interfacename.

fakealot files --out ./out --dir ./test [--tsconfig ./tsconfig.json]

Options

| Name | Type | Description | |---|---|---| | --dir | string | Directory path where all the interfaces are stored in. Dir will be searched recursive| | --out | string | Folder where all files will be created | | --tsconfig | string - optional | Path to the tsconfig file

Create a directory out with files in it. Each file then contains directly the interface data like this:

ComplexInterface.ts

export default interface ComplexInterface {
    type: string;
    
    /**
     * @minimum 2
     * @maximum 2
     */
    items: IItem[];
    
}

export interface IItem {
    name: string;
    
    /**
     * @minimum 0
     * @type integer
     */
    position: number;
}

ComplexInterface.json

{
    "items": [
        {
            "name": "dolore in qui et",
            "position": 70112329
        },
        {
            "name": "tempor anim irure laborum",
            "position": 77636896
        }
    ],
    "type": "aute dolor id enim culpa"
}

file

The file command will create a file, which stores a a collection with fake data for all interfaces found in the dir

The command

fakealot file --file ./mock.json --dir ./interfaces --tsconfig ./tsconfig.json

Options

| Name | Type |Description | |---|---|---| | --dir | string | Directory path where all the interfaces are stored in. Dir will be searched recursive| | --file | string | Path to file where the data will be dumped | | --tsconfig | string - optional | Path to the tsconfig file

will create a new file name mock.json

with the content

{
    "ComplexInterface": {
        "items": [
            {
                "name": "laboris ut",
                "position": 76655555
            },
            {
                "name": "ullamco officia esse",
                "position": 82465766
            }
        ],
        "type": "occaecat do"
    },
    "FakerInterface": {
        "finance": "696.47",
        "paragraphs": "Molestiae tempora eligendi omnis quisquam. Quos nihil dolor voluptatibus velit nobis culpa deleniti. Reprehenderit in nisi et. Quia odio et inventore eligendi in deserunt id. Sit odio quia vitae provident quo provident molestiae.\n \rPariatur quos est quod laborum. Quisquam esse quia expedita commodi. Tempora ut exercitationem doloribus harum. Sunt omnis et accusantium et quia quos sequi molestiae. Enim necessitatibus molestiae.\n \rEligendi rerum excepturi et laudantium fuga similique fugit corporis voluptatem. Esse nobis et sint magnam aut. Dolores maiores incidunt occaecati iusto laborum. Quia deleniti dolorem quibusdam id veniam perspiciatis et nisi. Corporis laboriosam esse. Soluta accusamus officiis ut excepturi blanditiis libero ut.",
        "word": "qui"
    },
    "LangSwitch": {
        "isActive": "yes",
        "languages": [
            {
                "label": "velit Excepteur consectetur eiusmod",
                "path": "ad"
            },
            {
                "label": "sunt",
                "path": "est"
            },
            {
                "label": "eu nulla mollit",
                "path": "ut dolore amet"
            },
            {
                "label": "commodo",
                "path": "cillum "
            }
        ],
        "type": "Enim tempore non voluptas quia vitae ipsam. Necessitatibus et dolor adipisci dolores sunt non explicabo occaecati. Nesciunt et sint est asperiores sit voluptatum mollitia enim iste. Nesciunt minima sequi voluptas optio aut voluptatem. Eligendi voluptates iste eius iure commodi molestiae. Voluptas quo ex reprehenderit ipsa incidunt corporis vel in."
    },
    "MultiFileInterface": {
        ...
    }
}

api

This command creates a server which then can be accessed from you App. By passing the interface name to the route, data with the same structure as the interface is served.

    fakealot api --port 3000 --dir ./SRC --tsconfig ./tsconfig.json

now by visting http://localhost:3000/api/schema/{INTERFACENAME} you'll get some mocked data.

Options

| Name | Type |Description | |---|---|---| | --dir | string | Directory path where all the interfaces are stored in. Dir will be searched recursive| | --port | number | Port number | --tsconfig | string - optional | Path to the tsconfig file

Interface

export default interface LangSwitch {
    /**
     * Type definition
     * @faker lorem.paragraph
     */
    type: string;

    /**
     * Type definition
     * @pattern yes|no
     */
    isActive: string;
    
    languages: ILink[];
}

export interface ILink {
    path: string;
    label: string;
    external?: boolean;
    icon?: IIcon;
}

export interface IIcon {
    symbol: string;
    size: string;
    dynamicSize?: boolean;
}

HTTP Response

{
    "isActive": "no",
    "languages": [
        {
            "label": "irure Exce",
            "path": "Excepteur"
        },
        {
            "label": "minim incididunt proident",
            "path": "elit exercitation"
        },
        {
            "label": "Lorem commodo",
            "path": "exercitation occaecat laborum"
        },
        {
            "label": "ea sit nostrud aute",
            "path": "aute"
        }
    ],
    "type": "Culpa nihil quia quis porro voluptatem vel. Libero fugiat doloremque deserunt quidem totam aperiam tempore. Reprehenderit rem cumque quia delectus perspiciatis sunt et. Et officia repellat. Assumenda excepturi sunt et aut corporis cumque quos distinctio. Ab quia autem consectetur occaecati nemo molestiae nisi temporibus soluta."
}