# ts-specification

> Specification pattern implementation for NodeJS in TypeScript

Latest version **2.2.1** (published 2016-09-13) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install ts-specification
pnpm add ts-specification
yarn add ts-specification
bun add ts-specification
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2016-09-13 |
| First published | 2016-06-12 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Georges Alkhouri |
| Maintainers | georgesalkhouri |
| Keywords | specification, specification-pattern, spec, pattern, node, ts, typescript |

## Links

- npm: https://www.npmjs.com/package/ts-specification
- Repository: https://github.com/GeorgesAlkhouri/ts-specification
- Homepage: https://github.com/GeorgesAlkhouri/ts-specification.git#README.md
- Issues: https://github.com/GeorgesAlkhouri/ts-specification.git/issues
- npm.io page: https://npm.io/package/ts-specification

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 2.2.1 (latest) — 2016-09-13
- 2.1.1 — 2016-07-23
- 2.1.0 — 2016-07-20
- 2.0.0 — 2016-06-26
- 1.0.0 — 2016-06-12

## README

Specification pattern for JavaScript implemented with TypeScript
================================================================

> In computer programming, the specification pattern is a particular software design pattern, whereby business rules can be recombined by chaining the business rules together using boolean logic.
>
> -- <cite>Wikipedia.org ( https://en.wikipedia.org/wiki/Specification_pattern )</cite>

Usage With Node
---------------

To use ts-specification with Node just run:

`npm install ts-specification`

and import the package afterwards:

`import Specification from 'ts-specification'`

The test cases are written in JavaScript and can be tested with:

`npm test`

Create Custom Specs
-------------------

To create custom specifications just extend from the `CompositeSpecification` class and implement the `isSatisfiedBy` function.

**TypeScript**

```
class RangeSpecification<T> extends CompositeSpecification<T> {

  private a: T
  private b: T

  constructor(a: T, b: T) {
      super()
      this.a = a
      this.b = b
  }

  isSatisfiedBy(candidate: T): boolean {
      return candidate >= this.a && candidate <= this.b
  }
}
```

**JavaScript**

```
import {CompositeSpecification} from 'ts-specification';

class TrueSpecification extends CompositeSpecification {

    isSatisfiedBy(candidate) {
        return true;
    }
}
```

---
_Source: https://npm.io/package/ts-specification · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
