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

intermock

v0.2.5

Published

Automatically create mock objects and JSON from TypeScript interfaces via Faker

Downloads

37,231

Readme

intermock Build Status

Mocking library to create mock objects and JSON for TypeScript interfaces via Faker.

This is not an officially supported Google product.

Installation

npm install intermock

CLI

Intermock exposes a CLI, which is the recommended way to use the tool. The following subsections show an example file, command, and output to demonstrate using the CLI.

Example file

interface Admin extends User {
   adminRecord: AdminRecord;
}

interface Student extends User {
   schoolRecord: SchoolRecord;
}

interface User {
   firstName: string;
   lastName: string;
   username: string;
   emailAddress: string;
}

interface AdminRecord {
   studentsPassedEachYear: number[];
}

interface SchoolRecord {
   startDate: string;
   endDate: string;
   isActive: boolean;
   grades: number[];
}

Example command

node ./node_modules/intermock/build/src/cli/index.js --files ./example-file.ts --interfaces "Admin"

Example output

{
  "Admin": {
    "firstName": "Willa",
    "lastName": "Walker",
    "username": "Shyann_Mante",
    "emailAddress": "[email protected]",
    "adminRecord": {
      "studentsPassedEachYear": [
        80342,
        23404,
        12854,
        74937,
        38185,
        73316
      ]
    }
  },

API Usage

Intermock’s API exports only one function, as seen below:

Function

// Returns an object or string based on `output` property specified in `Options`
mock(options: Options): object|string

Options

export interface Options {
 // Array of file tuples. (filename, data)
 files?: Array<[string, string]>;

 // TypeScript is currently the only supported language
 language?: SupportedLanguage;

 // Specific interfaces to write to output
 interfaces?: string[];

 // Used for testing mode,
 isFixedMode?: boolean;

 // One of object|json|string. Strings have their object's functions
 // stringified.
 output?: OutputType;

 // Should optional properties always be enabled
 isOptionalAlwaysEnabled?: boolean;
}

Type Support

The following TypeScript features are supported:

  • Interfaces
  • Interfaces with properties of primitive types
  • Interfaces with property references to other complex types
  • Interfaces with extensions
  • Unions
  • Type aliases
  • Arrays
  • Namespaces
  • Tuples
  • Mapped types
  • Generics
  • Functions (stringified output!)
  • Optional properties
  • Specific Faker data types (via JSDoc comment)
    interface Host {
      /** @mockType {internet.ipv6} */
      addr: string;
    }

Building

npm run build

Development

If you want to run the build script and tests after you save a file while developing, run the following command: npm run test-watch

Docs

Developing Docs

To develop documentation run the following commands:

npm run build
npm run docs-serve

Edit the files in docs/ and Webpack's Dev Server should auto-reload when there are changes

Statically Building Docs

To build the docs statically run the following command:

npm run build
npm run docs-build

Contributing

  1. Read all of CONTRIBUTING.md in this repo
  2. Sign the CLA
  3. In a terminal, run npm run ci
  4. Fix any linting, formatting, and/or compiling errors. (Note: Format errors can be fixed by npm run format. DO NOT fix linting errors by disabling the linter on a line and/or block)
  5. Create a Pull Request
  6. Address all comments, if any
  7. If everything looks good after comments are addressed, your PR will be merged!

License

See LICENSE in this repo