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

ibi

v0.4.0

Published

A set of tools for working with code on interfaces-based.

Downloads

3

Readme

Interface-based instructions

A set of tools for working with code on interfaces-based. It is best to use together with tx-reflector.

npm i --save-dev ibi

Features

  • Create mocks by interface
  • "Code generation" on interfaces-based
  • Creating Regression Tests

Create mocks by interface

See tx-reflector configuration

npm i --save-dev ibi tx-reflector
import {createMockFactory} from 'ibi';
import {getRawInterfaces} from 'tx-reflector';

interface IProps {
	name: string
	type: string;
	checked: boolean;;
}

const mock = createMockFactory<IProps>({
	interfaces: getRawInterfaces<IProps>(),
});

mock(); // {name: "", type: "", checked: false};
mock({checked: true}); // {name: "", type: "", checked: true};

Code Generation

const factory: IDeclarationFactory = createDeclarationFactory<T>(
	args: string[],
	defaultHandle(...args) => void,
);

// Where
//   - <T> — Interface of the result-object
//   - args — Array of variable names, the first is a reference to the result-object, the second source-object

interface IDeclarationFactory {
	// Register rules for the `T`-interface
	register<T>(name: string, rules: IRules) => ((...args) => object);

	// Run all registered rules
	exec(names: string[], ...args) => void;
}

interface IRules {
	[propName: string]: true | (handle(...args) => void);
}

An example of creating a function for generating DOM-properties based on the input props.

import {createGenerator} from 'ibi';

// Source interface
interface IInputProps {
	name: string;
	value: string;
	disabled?: boolean;
	onInput: (evt: Event) => void;
}

// Result interface
interface IInputDOMAttrs extends IInputProps {
	'aria-disabled': boolean;
}

// Create a factory of declarations
const domAttrs = createDeclarationFactory<IInputDOMAttrs>(
	['attrs', 'srcProps', 'classNames', 'css'],
	(prop, value, attrs, srcProps) => { // Processing `true`
		(srcProps[prop] != null) && (attrs[prop] = srcProps[prop]);
	}
);

// Register the conversion function for `IInputProps`
const inputPropsToAttrs = domAttrs.register<IInputProps>('IInputProps', {
	name: true, // Transfer "as is"
	value: true,
	disabled(prop, value, attrs, srcProps, classNames, css) {
		// In this handler, except `disabled`,
		// define `aria-disabled` and into `classNames` add `css.isDisabled`.
		attrs[prop] = value;

		if (value) {
			attrs[`aria-${prop}`] = value + '';
			classNames.push(css.isDisabled);
		}
	},
	onInput(prop, value, attrs, srcProps) {
		// Add the listener only if not `disabled`
		attrs[prop] = srcProps.disabled ? null : value;
	},
});


// Somewhere in the code, for example React-like component
import css from './Input.css';

export default function InputComponent(props: IInputProps) {
	const attrs = {};
	const classNames = [css.input]; // базовый класс

	inputPropsToAttrs(attrs, props, classNames, css);
	// or domAttrs.exec(['IInputProps'], attrs, props, classNames, css);
	// or better still, if  use `tx-reflector`:
	//   domAttrs.exec(getComponentInterfaces<IInputProps>(this), attrs, props, classNames, css);

	return <input {...attrs} className={classNames.join(' ')}/>;
}

Regressions

Laziness to write an example, so look tests

// ...

Development