1
- # is- class-decorator
1
+ # class-is
2
2
3
3
[ ![ NPM version] [ npm-image ]] [ npm-url ] [ ![ Downloads] [ downloads-image ]] [ npm-url ] [ ![ Build Status] [ travis-image ]] [ travis-url ] [ ![ Coverage Status] [ codecov-image ]] [ codecov-url ] [ ![ Dependency status] [ david-dm-image ]] [ david-dm-url ] [ ![ Dev Dependency status] [ david-dm-dev-image ]] [ david-dm-dev-url ] [ ![ Greenkeeper badge] [ greenkeeper-image ]] [ greenkeeper-url ]
4
4
5
- [ npm-url ] :https://npmjs.org/package/is- class-decorator
6
- [ downloads-image ] :http://img.shields.io/npm/dm/is- class-decorator .svg
7
- [ npm-image ] :http://img.shields.io/npm/v/is- class-decorator .svg
8
- [ travis-url ] :https://travis-ci.org/moxystudio/js-is- class-decorator
9
- [ travis-image ] :http://img.shields.io/travis/moxystudio/js-is- class-decorator /master.svg
10
- [ codecov-url ] :https://codecov.io/gh/moxystudio/js-is- class-decorator
11
- [ codecov-image ] :https://img.shields.io/codecov/c/github/moxystudio/js-is- class-decorator /master.svg
12
- [ david-dm-url ] :https://david-dm.org/moxystudio/js-is- class-decorator
13
- [ david-dm-image ] :https://img.shields.io/david/moxystudio/js-is- class-decorator .svg
14
- [ david-dm-dev-url ] :https://david-dm.org/moxystudio/js-is- class-decorator ?type=dev
15
- [ david-dm-dev-image ] :https://img.shields.io/david/dev/moxystudio/js-is- class-decorator .svg
16
- [ greenkeeper-image ] :https://badges.greenkeeper.io/moxystudio/js-is- class-decorator .svg
5
+ [ npm-url ] :https://npmjs.org/package/class-is
6
+ [ downloads-image ] :http://img.shields.io/npm/dm/class-is .svg
7
+ [ npm-image ] :http://img.shields.io/npm/v/class-is .svg
8
+ [ travis-url ] :https://travis-ci.org/moxystudio/js-class-is
9
+ [ travis-image ] :http://img.shields.io/travis/moxystudio/js-class-is /master.svg
10
+ [ codecov-url ] :https://codecov.io/gh/moxystudio/js-class-is
11
+ [ codecov-image ] :https://img.shields.io/codecov/c/github/moxystudio/js-class-is /master.svg
12
+ [ david-dm-url ] :https://david-dm.org/moxystudio/js-class-is
13
+ [ david-dm-image ] :https://img.shields.io/david/moxystudio/js-class-is .svg
14
+ [ david-dm-dev-url ] :https://david-dm.org/moxystudio/js-class-is ?type=dev
15
+ [ david-dm-dev-image ] :https://img.shields.io/david/dev/moxystudio/js-class-is .svg
16
+ [ greenkeeper-image ] :https://badges.greenkeeper.io/moxystudio/js-class-is .svg
17
17
[ greenkeeper-url ] :https://greenkeeper.io/
18
18
19
19
Enhances a JavaScript class by adding an ` is<Class> ` property to compare types between realms.
@@ -28,13 +28,13 @@ So the solution is to use symbols.
28
28
29
29
## Installation
30
30
31
- ` $ npm install is-class-decorator `
32
-
31
+ ` $ npm install class-is `
33
32
34
33
## Usage
35
34
36
35
``` js
37
- import addIs from ' is-class-decorator' ;
36
+ // Package X
37
+ import withIs from ' is-class-decorator' ;
38
38
39
39
class Person {
40
40
constructor (name , city ) {
@@ -43,20 +43,26 @@ class Person {
43
43
}
44
44
}
45
45
46
+ export default withIs (Person, { className: ' Person' , symbolName: ' @org/package-x/person' });
47
+
48
+ // Package Y
46
49
class Animal {
47
50
constructor (species ) {
48
51
this .species = species;
49
52
}
50
53
}
51
54
52
- const PersonWithType = addIs (' Person' )(Person);
53
- const AnimalWithType = addIs (' Animal' )(Animal);
55
+ export default withIs (Animal, { className: ' Animal' , symbolName: ' @org/package-y/animal' });
54
56
55
- const diogo = new PersonWithType (' Diogo' , ' Porto' );
56
- const wolf = new AnimalWithType (' Wolf' );
57
+ // Package Z
58
+ import Person from ' package-x' ;
59
+ import Animal from ' package-y' ;
57
60
58
- console .log (PersonWithType .isPerson (diogo));
59
- console .log (PersonWithType .isPerson (wolf));
61
+ const diogo = new Person (' Diogo' , ' Porto' );
62
+ const wolf = new Animal (' Gray Wolf' );
63
+
64
+ console .log (Person .isPerson (diogo));
65
+ console .log (Person .isPerson (wolf));
60
66
```
61
67
62
68
Running the example above will print:
66
72
false
67
73
```
68
74
75
+ ## API
76
+
77
+ ### withIs(Class, { className: name, symbolName: symbol })
78
+
79
+ ###### class
80
+
81
+ Type: ` class `
82
+
83
+ The class to be enhanced.
84
+
85
+ ###### className
86
+
87
+ Type: ` String `
88
+
89
+ The name of the class your passing.
90
+
91
+ ###### symbolName
92
+
93
+ Type: ` String `
94
+
95
+ Unique * id* for the class. This should be namespaced so different classes from different modules do not collide and give false positives.
96
+
97
+ Example: ` @organization/package/class `
98
+
69
99
## Tests
70
100
71
101
` $ npm test `
0 commit comments