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

spoeck

v0.0.11

Published

Specification pattern implementation

Downloads

11

Readme

Spoeck

Specification pattern library written in typescript.

Create a specification :

import { createSpec } from 'spoeck';

const dragon = {
  color: 'blue',
  element: 'ice',
  age: 1000,
};

const dragonIsBlue = createSpec({
  name: 'dragonIsBlue',
  desc: 'Dragon is blue',
  isSatisfiedBy: (dragon: Dragon) => dragon.color === 'blue'
});

const result = dragonIsBlue.isSatisfiedBy(dragon);

const result.value // => true

Result format :

The specification isSatisifiedBy function will always return an object with these properties.

  • name: Is the name of the specification.
  • desc: Is the description of the specification.
  • value: Is the boolean that indicate if the specification is respected.
  • details: Is the list of all sub specifications results.
// With a simple rule :
const result ={
  name: 'dragonIsBlue',
  desc: 'Dragon is blue',
  value: true,
  details: [
    { name: 'dragonIsBlue', desc: 'Dragon is blue', value: true },
  ],
};

// With a composite rule :
 const dragonIsBlueIceYoung = dragonIsBlue
  .and(dragonIsIce, 'dragonIsBlueIce')
  .and(dragonIsYoung, 'dragonIsBlueIceYoung');

const compositeRuleResult = {
  name: 'dragonIsBlueIceYoung',
  desc: 'Dragon is blue AND (Dragon is ice) AND (NOT (Dragon is old))',
  value: false,
  details: [
    { name: 'dragonIsBlue', desc: 'Dragon is blue', value: true },
    { name: 'dragonIsIce', desc: 'Dragon is ice', value: true },
    { name: 'dragonIsYoung', desc: 'NOT (Dragon is old)', value: false },
  ],
}

Combining specifications with operator :

AND operator:

import { createSpec } from 'spoeck';

const dragon = {
  color: 'blue',
  element: 'ice',
  age: 1000,
};

const dragonIsBlue = createSpec({
  name: 'dragonIsBlue',
  desc: 'Dragon is blue',
  isSatisfiedBy: (dragon: Dragon) => entity.color === 'blue'
});

const dragonIsIce = createSpec({
  name: 'dragonIsIce',
  desc: 'Dragon is ice',
  isSatisfiedBy: (dragon: Dragon) => entity.element === 'ice'
});

const dragonIsBlueANDIce = dragonIsBlue.and(dragonIsIce, 'dragonIsBlueANDIce');

const result = dragonIsBlueANDIce.isSatisfiedBy(dragon);

result.value; // => true

OR operator :

const dragonIsBlueORIce = dragonIsBlue.or(dragonIsIce, 'dragonIsBlueORIce');

const result = dragonIsBlueORIce.isSatisfiedBy(dragon);

result.value; // => true

XOR operator :

const dragonIsBlueXORIce = dragonIsBlue.xor(dragonIsIce, 'dragonIsBlueXORIce');

const result = dragonIsBlueXORIce.isSatisfiedBy(dragon);

result.value; // => false

NOT operator :

const dragonIsBlueAndNotIce = dragonIsBlue.and(dragonIsIce.not('dragonIsNotIce'), 'dragonIsBlueAndNotIce');

const result = dragonIsBlueAndNotIce.isSatisfiedBy(dragon);

result.value; // => false