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

view-models

v3.1.0

Published

Generate viewmodels from react components

Downloads

57

Readme

ViewModels

npm version

Tools for converting type definitions in client side apps to type definitions in server-side languages. Currently supports converting types from React or TypeScript/React to C#, Kotlin or TypeScript.

These tools were developed for adding type safety to websites that employ server-side rendering where the client and server use different languages (like rendering React components in C# using ReactJS.NET). Combining this with CI/CD helps uncover breaking changes in the client/server integration before they reach end users.

npm install --save-dev view-models

Table of contents

TLDR usage

CLI

To see the CLI help, run view-models --help.

Read more here

Webpack plugin

Config example. See complete list of options here

const ViewModelsPlugin = require('view-models/webpack-plugin');
const { generators, parsers } = require('view-models');

module.exports = {
  entry: { ... },
  output: { ... },
  plugins: [
    new ViewModelsPlugin({
      include: [/\.tsx$/],
      exclude: ['node_modules', 'some/path/to/exclude'],
      compilerOptions: {
        parser: parsers.typescriptReact, // Optional
        generator: generators.kotlin // Optional
      }
    })
  ]
};

Babel plugin

Read more here

{
  "plugins": ["view-models/babel-plugin"]
}

Eslint plugin

Read more here

npm install --save-dev eslint-plugin-view-models

{
  "plugins": ["eslint-plugin-view-models"],
  "rules": {
    "view-models/no-errors": "error",
    "view-models/no-unused-meta": "warn",
    "view-models/no-meta-mismatch": "warn",
    "view-models/no-prop-mapping": "warn"
  }
}

Reliability

Only some of the parsers/generators in this package have been properly tested:

  • JavaScript-React parser: used in production since 2018
  • Typescript-React parser: experimental
  • C# generator: used in production since 2018
  • TypeScript generator: used in production since 2020
  • Kotlin generator: experimental

Docs

Tools

Parsers

Generators

About

This is a TypeScript rewrite of @creuna/prop-types-csharp which I created while employed at Creuna. At Creuna we started using ReactJS.NET for server-side rendering pretty heavily around 2017 and soon discovered that a javascript/C# integration can be quite brittle. Breakage was common. I introduced this tool mid-2018 and since sorting out the initial kinks it has been very helpful in reducing runtime breakage.

If you're migrating from @creuna/prop-types-csharp here's a migration guide.