https://github.com/georgesalkhouri/ts-specification
Specification pattern implementation for NodeJS in TypeScript
https://github.com/georgesalkhouri/ts-specification
javascript specification-pattern typescript
Last synced: 10 months ago
JSON representation
Specification pattern implementation for NodeJS in TypeScript
- Host: GitHub
- URL: https://github.com/georgesalkhouri/ts-specification
- Owner: GeorgesAlkhouri
- License: apache-2.0
- Created: 2016-05-16T20:17:32.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-28T20:36:50.000Z (over 9 years ago)
- Last Synced: 2025-03-24T20:11:26.409Z (11 months ago)
- Topics: javascript, specification-pattern, typescript
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 17
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Specification pattern for JavaScript implemented with TypeScript
================================================================
[](https://travis-ci.org/GeorgesAlkhouri/ts-specification)
> 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.
>
> -- Wikipedia.org ( https://en.wikipedia.org/wiki/Specification_pattern )
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 extends CompositeSpecification {
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;
}
}
```