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

@nanomatic/design_patterns

v1.0.0

Published

Implementation of the all design patterns

Downloads

6

Readme

Status License


📝 Table of Contents

🏁 Getting Started

Installing

npm i @nanomatic/design_patterns

Using

Example code below:

import { Command, Commands } from '@nanomatic/design_patterns'

const add = (x: number = 0, y: number = 0) => x + y;
const sub = (x: number = 0, y: number = 0) => x - y;
const mul = (x: number = 0, y: number = 0) => x * y;
const div = (x: number = 0, y: number = 0) => x / y;

const addCommand = (value: number = 0) => new Command(add, sub, value);
const subCommand = (value: number = 0) => new Command(sub, add, value);
const mulCommand = (value: number = 1) => new Command(mul, div, value);
const divCommand = (value: number = 1) => new Command(div, mul, value);

// Helper function
const showResult = ({ getValue }: Commands) => console.log(`Result: ${getValue()}`);

const calculator = new Commands(0);         // Initial value.

calculator.add(addCommand(20));             // Add to queue without execute.
calculator.add(subCommand(16)).execute();   // Be aware - the first command in the queue will be executed only!
calculator.add(mulCommand(2)).execute();    // Be aware - the second command in the queue will be executed only!
calculator.add(divCommand(4)).execute();    // Be aware - the third command in the queue will be executed only!

calculator.execute();                       // You have to execute last command by calling "execute" method once again.

calculator.undo(3);                         // You can also undo some commands...
calculator.redo(3);                         // ...or redo how many times you want.

showResult(calculator);

calculator.clear();                         // Clear all pervious commands.

// ---------------------------------------------------------
// At every time, you can easly pass all commands as a array
// ---------------------------------------------------------
calculator.add([
    addCommand(20),
    subCommand(16),
    mulCommand(2),
    divCommand(4)
]).redoAll();                               // Execute all commands by calling "redoAll" method instead of "execute" 3 times.

calculator.undoAll();                       // You can also undo all commands...
calculator.redo(3);                         // ...or redo how many times you want.

calculator.execute(addCommand(2));          // It's possible to execute new command directly

showResult(calculator);

⛏️ Built With

✍️ Authors