collection-decorator
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "collection-decorator", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Decorator for adding to collection", | ||
@@ -48,3 +48,3 @@ "main": "dist/index.js", | ||
"collectCoverage": true, | ||
"coverageDirectory": "../coverage", | ||
"coverageDirectory": "./coverage", | ||
"collectCoverageFrom": [ | ||
@@ -51,0 +51,0 @@ "src/**/*.ts" |
# collection-decorator | ||
Decorator for adding to collection | ||
[![npm](https://img.shields.io/npm/v/collection-decorator)](https://www.npmjs.com/package/collection-decorator) | ||
[![Build status](https://img.shields.io/travis/iamolegga/collection-decorator.svg)](https://travis-ci.org/iamolegga/collection-decorator) | ||
[![Coverage Status](https://coveralls.io/repos/github/iamolegga/collection-decorator/badge.svg?branch=master)](https://coveralls.io/github/iamolegga/collection-decorator?branch=master) | ||
![David](https://img.shields.io/david/iamolegga/collection-decorator) | ||
Typical usecase for this library: | ||
```ts | ||
// HasFoo.ts | ||
import { createCollectionDecorator } from 'collection-decorator'; | ||
interface ClassType { | ||
foo: number; | ||
} | ||
const { collection, decorator } = | ||
createCollectionDecorator<ClassType>(); | ||
export function fooSum() { | ||
let sum = 0; | ||
for (let value of collection.values()) { | ||
sum += value.foo | ||
} | ||
return sum; | ||
} | ||
export const HasFoo = decorator; | ||
``` | ||
```ts | ||
// A.ts | ||
import { HasFoo } from './HasFoo.ts'; | ||
@HasFoo | ||
export class A { | ||
static foo = 1; | ||
} | ||
``` | ||
```ts | ||
// B.ts | ||
import { HasFoo } from './HasFoo.ts'; | ||
@HasFoo | ||
//^^^^^ TS error because class B has not `foo` property | ||
export class B {} | ||
// So fix it: | ||
@HasFoo | ||
export class B { | ||
static foo = 2; | ||
} | ||
``` | ||
```ts | ||
// sum.ts | ||
import { fooSum } from './HasFoo.ts'; | ||
fooSum() // 3 | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6611
65