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

createprops

v0.5.5

Published

Create Svelte component props

Downloads

537

Readme

Overview

This script will create json files in the src/routes/props directory. This script is created for Svelte and please let me know if it works for other framework.

Installation

npm i -D createprops

Usage

In your package.json add the following link in the scripts:

"scripts": {
  ...
  "props": "node ./node_modules/createprops/createprops.js"
},

The default value for destination is ./src/routes/props. You can change it using --dest:

"scripts": {
  ...
  "props": "node ./node_modules/createprops/createprops.js --dest ./props/"
},

The default value for lib directory is ./src/lib. You can change it using --src:

"scripts": {
  ...
  "props": "node ./node_modules/createprops/createprops.js --src ./src/mylib-dir"
},

Example

From ./src/lib/Aside.svelte:

export let transitionParams: TransitionParamTypes = {};
export let transitionType: TransitionTypes = 'fly';
export let asideClass: string = 'absolute w-auto h-screen bg-gray-200 border-r-2 shadow-lg';

To ./src/routes/props/Aside.json:

{
  "props": [
    ["transitionParams", " TransitionParamTypes ", " {}"],
    ["transitionType", " TransitionTypes ", " 'fly'"],
    ["asideClass", " string ", " 'absolute w-auto h-screen bg-gray-200 border-r-2 shadow-lg'"]
  ]
}

Limitation

  1. All exported props must end with ;

The script uses ; to split lines. If you are using VS code, it automatically inserts ; at the end of each line when you save a file.

// 💩 no ; at the end
export let myvar: string = 'bla bla';

// good
export let myvar: string = 'bla bla';
  1. Set all the exported props at the top after import statements.
// 💩 no
$: if (color && isOpen) {
  buttonClass = btnClass + colorClass;
} else {
  buttonClass = btnClass;
}
export let iconSize: number = 24;

// good
export let iconSize: number = 24;
$: if (color && isOpen) {
  buttonClass = btnClass + colorClass;
} else {
  buttonClass = btnClass;
}
  1. Does not extract functions

Currently the script is not able to extract functions.

// can't do it
export function greet(name) {
  alert(`hello ${name}!`);
}

// can't do it
export const myfunc = (name) => {
  open = !open;
};
  1. Does not extract multi-layered objects
// can do
export let icons: AccordionIconType = {
  up: ChevronUpSolid,
  down: ChevronDownSolid
};

// can't do it

Prop tables

You can create a table using Flowbite-Svelte's Table and TableDefaultRow components.

npm i -D flowbite-svelte
<script>
  import { Table, TableDefaultRow } from 'flowbite-svelte';
  // import your prop file
  import componentProps from '../Card/.json'
  // Props table
  let items = componentProps.props
  let propHeader = ['Name', 'Type', 'Default']

  let divClass='w-full relative overflow-x-auto shadow-md sm:rounded-lg py-4'

  let theadClass ='text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-white'
</scipt>

<Table header={propHeader} {divClass} {theadClass}>
  <TableDefaultRow {items} rowState='hover' />
</Table>

Example

example

Example

License

Please see license.txt.