├── .gitignore
├── .npmignore
├── .travis.yml
├── LICENSE
├── README.md
├── cjs
└── index.js
├── coverage
├── coverage.json
├── lcov-report
│ ├── base.css
│ ├── endow
│ │ ├── cjs
│ │ │ ├── index.html
│ │ │ └── index.js.html
│ │ ├── index.html
│ │ └── test.js.html
│ ├── index.html
│ ├── prettify.css
│ ├── prettify.js
│ ├── sort-arrow-sprite.png
│ └── sorter.js
└── lcov.info
├── esm
└── index.js
├── index.js
├── min.js
├── package.json
└── test.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | coverage/*
2 | esm/.eslintrc
3 | node_modules/*
4 | test.js
5 | .DS_Store
6 | .gitignore
7 | .travis.yml
8 | package-lock.json
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - stable
4 | git:
5 | depth: 1
6 | branches:
7 | only:
8 | - master
9 | after_success:
10 | - "npm run coveralls"
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | ISC License
2 |
3 | Copyright (c) 2018, Andrea Giammarchi, @WebReflection
4 |
5 | Permission to use, copy, modify, and/or distribute this software for any
6 | purpose with or without fee is hereby granted, provided that the above
7 | copyright notice and this permission notice appear in all copies.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 | PERFORMANCE OF THIS SOFTWARE.
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # endow [](https://coveralls.io/github/WebReflection/endow?branch=master) [](https://travis-ci.org/WebReflection/endow) [](https://opensource.org/licenses/ISC)
2 |
3 | A minimalistic, yet powerful, class based mixin utility.
4 |
5 | Following an approach explained in [this post](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/),
6 | and inspired by one piece of [the following utility](https://github.com/justinfagnani/mixwith.js#mixwith),
7 | _endow_ makes creation of mixins a no-brainer, giving the ability to use `instanceof` operator.
8 |
9 | ```js
10 | // define mixins through this class based pattern
11 | const Mixin1 = Super => class extends Super {
12 | behavior1() {}
13 | };
14 | const Mixin2 = Super => class extends Super {
15 | behavior2() {}
16 | };
17 |
18 | // endow classes with mixins while extending
19 | class Sub extends endow(Super).with(Mixin1, Mixin2) {
20 | behaviors() {
21 | this.behavior1();
22 | this.behavior2();
23 | }
24 | }
25 |
26 | new Sub instanceof Sub; // true
27 | new Sub instanceof Super; // true
28 | new Sub instanceof Mixin1; // true
29 | new Sub instanceof Mixin2; // true
30 | ```
31 |
32 | ### How to include
33 |
34 | * _ESM_ via `import endow from 'endow/esm'`
35 | * _CJS_ via `const {endow} = require('endow/cjs');`
36 | * browsers via [unpkg.com/endow](https://unpkg.com/endow)
37 |
38 |
39 | ### Compatibility
40 |
41 | This module syntax is purposely written in an ES3 compatible fashion.
42 |
43 | ES5 [Array#some](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) and [Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) are needed,
44 | and to have a proper `instanceof` operator result, the [Symbol.hasInstance](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance) is needed too,
45 | but it's not mandatory.
46 |
47 | Please note this utility works with all polyfills (loaded upfront) and transpilers too.
48 |
49 | #### Size
50 |
51 | * plain `index.js` is 2535 bytes
52 | * plain `min.js` is 499 bytes
53 | * gzip `min.js` is 337 bytes
54 | * brotli `min.js` is 277 bytes
55 |
--------------------------------------------------------------------------------
/cjs/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /*! (c) Andrea Giammarchi, @WebReflection (ISC) */
3 | // inspired by https://github.com/justinfagnani/mixwith.js#mixwith
4 |
5 | // If not available, Symbol could even be a special `String` here
6 | var classes = Symbol('endow');
7 |
8 | // fallback to same symbol, ignore hasInstance completely
9 | // in this case code will be transpiled and the result
10 | // of every instanceof will be simply false
11 | var hasInstance = Symbol.hasInstance || classes;
12 |
13 | // Symbol.hasInstance descriptor is always the same
14 | // no need to pollute GC with useless garbage
15 | var descriptor = {
16 | configurable: true,
17 | value: function (object) {
18 | return this[classes].some(instanceOf, object);
19 | }
20 | };
21 |
22 | // endow can be imported as default or as {endow}
23 | Object.defineProperty(exports, '__esModule', {value: true}).default = endow;
24 | function endow(Super) {
25 | return {
26 | // IE < 9 might throw with code that uses `{with: ...}`
27 | "with": function () {
28 | for (var
29 | Mixin,
30 | Class = Super,
31 | i = 0, length = arguments.length; i < length; i++
32 | ) {
33 | Mixin = arguments[i];
34 | Class = Mixin(Class);
35 | // A Mixin knows all classes it extended.
36 | // there is no iterable WeakSet to do this,
37 | // so derived classes are retained once.
38 | // This should not be a real-world issue
39 | // because classes are usually a pre-defined,
40 | // well known, amount.
41 | // If you create a lot of classes on the fly though,
42 | // and you'd like to use endow, be sure you drain
43 | // that Mixin list from time to time.
44 | //
45 | // Object.getOwnPropertySymbols(Mixin)
46 | // .some(s => /\bendow\b/.test(String(s)) && Mixin[s].splice(0));
47 | //
48 | // Please note after that instanceof operations won't be reliable.
49 | // If you create a lot of classes on the fly though, most likely
50 | // you won't ever need instanceof against Mixins.
51 | if (has(Mixin, classes)) {
52 | Mixin[classes].push(Class);
53 | } else if (!has(Mixin, hasInstance)) {
54 | define(Mixin, Class, {});
55 | }
56 | }
57 | return Class;
58 | }
59 | };
60 | }
61 | exports.endow = endow
62 |
63 | // order matters. In case of a fallback to same symbol
64 | // the Symbol.hasInstance is ignored/overwritten
65 | function define(Mixin, Class, descriptors) {
66 | descriptors[hasInstance] = descriptor;
67 | descriptors[classes] = {value: [Class]};
68 | Object.defineProperties(Mixin, descriptors);
69 | }
70 |
71 | // minifier friendly shortcut
72 | function has(object, value) {
73 | return object.hasOwnProperty(value);
74 | }
75 |
76 | // handy array.some(...) helper
77 | function instanceOf(Class) {
78 | return this instanceof Class;
79 | }
80 |
--------------------------------------------------------------------------------
/coverage/coverage.json:
--------------------------------------------------------------------------------
1 | {"/Users/agiammarchi/git/endow/test.js":{"path":"/Users/agiammarchi/git/endow/test.js","s":{"1":1,"2":1,"3":3,"4":1,"5":2,"6":1,"7":1,"8":1,"9":1,"10":1,"11":1,"12":1,"13":1,"14":1,"15":1,"16":1,"17":1},"b":{},"f":{"1":1,"2":1},"fnMap":{"1":{"name":"(anonymous_1)","line":23,"loc":{"start":{"line":23,"column":52},"end":{"line":23,"column":55}}},"2":{"name":"(anonymous_2)","line":36,"loc":{"start":{"line":36,"column":11},"end":{"line":36,"column":28}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},"2":{"start":{"line":3,"column":0},"end":{"line":3,"column":46}},"3":{"start":{"line":3,"column":20},"end":{"line":3,"column":45}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":46}},"5":{"start":{"line":4,"column":20},"end":{"line":4,"column":45}},"6":{"start":{"line":10,"column":0},"end":{"line":20,"column":18}},"7":{"start":{"line":22,"column":0},"end":{"line":22,"column":46}},"8":{"start":{"line":22,"column":20},"end":{"line":22,"column":45}},"9":{"start":{"line":23,"column":0},"end":{"line":23,"column":75}},"10":{"start":{"line":23,"column":57},"end":{"line":23,"column":70}},"11":{"start":{"line":26,"column":0},"end":{"line":30,"column":18}},"12":{"start":{"line":32,"column":0},"end":{"line":32,"column":47}},"13":{"start":{"line":33,"column":0},"end":{"line":33,"column":23}},"14":{"start":{"line":34,"column":0},"end":{"line":34,"column":37}},"15":{"start":{"line":36,"column":0},"end":{"line":38,"column":2}},"16":{"start":{"line":37,"column":2},"end":{"line":37,"column":35}},"17":{"start":{"line":41,"column":0},"end":{"line":44,"column":18}}},"branchMap":{}},"/Users/agiammarchi/git/endow/cjs/index.js":{"path":"/Users/agiammarchi/git/endow/cjs/index.js","s":{"1":2,"2":2,"3":2,"4":7,"5":2,"6":1,"7":5,"8":5,"9":7,"10":7,"11":7,"12":3,"13":4,"14":3,"15":5,"16":2,"17":1,"18":3,"19":3,"20":3,"21":1,"22":11,"23":1,"24":13},"b":{"1":[2,1],"2":[3,4],"3":[3,1]},"f":{"1":7,"2":5,"3":5,"4":3,"5":11,"6":13},"fnMap":{"1":{"name":"(anonymous_1)","line":17,"loc":{"start":{"line":17,"column":9},"end":{"line":17,"column":27}}},"2":{"name":"endow","line":24,"loc":{"start":{"line":24,"column":0},"end":{"line":24,"column":22}}},"3":{"name":"(anonymous_3)","line":27,"loc":{"start":{"line":27,"column":12},"end":{"line":27,"column":24}}},"4":{"name":"define","line":65,"loc":{"start":{"line":65,"column":0},"end":{"line":65,"column":43}}},"5":{"name":"has","line":72,"loc":{"start":{"line":72,"column":0},"end":{"line":72,"column":28}}},"6":{"name":"instanceOf","line":77,"loc":{"start":{"line":77,"column":0},"end":{"line":77,"column":27}}}},"statementMap":{"1":{"start":{"line":6,"column":0},"end":{"line":6,"column":30}},"2":{"start":{"line":11,"column":0},"end":{"line":11,"column":48}},"3":{"start":{"line":15,"column":0},"end":{"line":20,"column":2}},"4":{"start":{"line":18,"column":4},"end":{"line":18,"column":50}},"5":{"start":{"line":23,"column":0},"end":{"line":23,"column":76}},"6":{"start":{"line":24,"column":0},"end":{"line":60,"column":1}},"7":{"start":{"line":25,"column":2},"end":{"line":59,"column":4}},"8":{"start":{"line":28,"column":6},"end":{"line":56,"column":7}},"9":{"start":{"line":33,"column":8},"end":{"line":33,"column":29}},"10":{"start":{"line":34,"column":8},"end":{"line":34,"column":29}},"11":{"start":{"line":51,"column":8},"end":{"line":55,"column":9}},"12":{"start":{"line":52,"column":10},"end":{"line":52,"column":37}},"13":{"start":{"line":53,"column":15},"end":{"line":55,"column":9}},"14":{"start":{"line":54,"column":10},"end":{"line":54,"column":35}},"15":{"start":{"line":57,"column":6},"end":{"line":57,"column":19}},"16":{"start":{"line":61,"column":0},"end":{"line":61,"column":21}},"17":{"start":{"line":65,"column":0},"end":{"line":69,"column":1}},"18":{"start":{"line":66,"column":2},"end":{"line":66,"column":40}},"19":{"start":{"line":67,"column":2},"end":{"line":67,"column":42}},"20":{"start":{"line":68,"column":2},"end":{"line":68,"column":46}},"21":{"start":{"line":72,"column":0},"end":{"line":74,"column":1}},"22":{"start":{"line":73,"column":2},"end":{"line":73,"column":38}},"23":{"start":{"line":77,"column":0},"end":{"line":79,"column":1}},"24":{"start":{"line":78,"column":2},"end":{"line":78,"column":31}}},"branchMap":{"1":{"line":11,"type":"binary-expr","locations":[{"start":{"line":11,"column":18},"end":{"line":11,"column":36}},{"start":{"line":11,"column":40},"end":{"line":11,"column":47}}]},"2":{"line":51,"type":"if","locations":[{"start":{"line":51,"column":8},"end":{"line":51,"column":8}},{"start":{"line":51,"column":8},"end":{"line":51,"column":8}}]},"3":{"line":53,"type":"if","locations":[{"start":{"line":53,"column":15},"end":{"line":53,"column":15}},{"start":{"line":53,"column":15},"end":{"line":53,"column":15}}]}}}}
--------------------------------------------------------------------------------
/coverage/lcov-report/base.css:
--------------------------------------------------------------------------------
1 | body, html {
2 | margin:0; padding: 0;
3 | height: 100%;
4 | }
5 | body {
6 | font-family: Helvetica Neue, Helvetica, Arial;
7 | font-size: 14px;
8 | color:#333;
9 | }
10 | .small { font-size: 12px; }
11 | *, *:after, *:before {
12 | -webkit-box-sizing:border-box;
13 | -moz-box-sizing:border-box;
14 | box-sizing:border-box;
15 | }
16 | h1 { font-size: 20px; margin: 0;}
17 | h2 { font-size: 14px; }
18 | pre {
19 | font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
20 | margin: 0;
21 | padding: 0;
22 | -moz-tab-size: 2;
23 | -o-tab-size: 2;
24 | tab-size: 2;
25 | }
26 | a { color:#0074D9; text-decoration:none; }
27 | a:hover { text-decoration:underline; }
28 | .strong { font-weight: bold; }
29 | .space-top1 { padding: 10px 0 0 0; }
30 | .pad2y { padding: 20px 0; }
31 | .pad1y { padding: 10px 0; }
32 | .pad2x { padding: 0 20px; }
33 | .pad2 { padding: 20px; }
34 | .pad1 { padding: 10px; }
35 | .space-left2 { padding-left:55px; }
36 | .space-right2 { padding-right:20px; }
37 | .center { text-align:center; }
38 | .clearfix { display:block; }
39 | .clearfix:after {
40 | content:'';
41 | display:block;
42 | height:0;
43 | clear:both;
44 | visibility:hidden;
45 | }
46 | .fl { float: left; }
47 | @media only screen and (max-width:640px) {
48 | .col3 { width:100%; max-width:100%; }
49 | .hide-mobile { display:none!important; }
50 | }
51 |
52 | .quiet {
53 | color: #7f7f7f;
54 | color: rgba(0,0,0,0.5);
55 | }
56 | .quiet a { opacity: 0.7; }
57 |
58 | .fraction {
59 | font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
60 | font-size: 10px;
61 | color: #555;
62 | background: #E8E8E8;
63 | padding: 4px 5px;
64 | border-radius: 3px;
65 | vertical-align: middle;
66 | }
67 |
68 | div.path a:link, div.path a:visited { color: #333; }
69 | table.coverage {
70 | border-collapse: collapse;
71 | margin: 10px 0 0 0;
72 | padding: 0;
73 | }
74 |
75 | table.coverage td {
76 | margin: 0;
77 | padding: 0;
78 | vertical-align: top;
79 | }
80 | table.coverage td.line-count {
81 | text-align: right;
82 | padding: 0 5px 0 20px;
83 | }
84 | table.coverage td.line-coverage {
85 | text-align: right;
86 | padding-right: 10px;
87 | min-width:20px;
88 | }
89 |
90 | table.coverage td span.cline-any {
91 | display: inline-block;
92 | padding: 0 5px;
93 | width: 100%;
94 | }
95 | .missing-if-branch {
96 | display: inline-block;
97 | margin-right: 5px;
98 | border-radius: 3px;
99 | position: relative;
100 | padding: 0 4px;
101 | background: #333;
102 | color: yellow;
103 | }
104 |
105 | .skip-if-branch {
106 | display: none;
107 | margin-right: 10px;
108 | position: relative;
109 | padding: 0 4px;
110 | background: #ccc;
111 | color: white;
112 | }
113 | .missing-if-branch .typ, .skip-if-branch .typ {
114 | color: inherit !important;
115 | }
116 | .coverage-summary {
117 | border-collapse: collapse;
118 | width: 100%;
119 | }
120 | .coverage-summary tr { border-bottom: 1px solid #bbb; }
121 | .keyline-all { border: 1px solid #ddd; }
122 | .coverage-summary td, .coverage-summary th { padding: 10px; }
123 | .coverage-summary tbody { border: 1px solid #bbb; }
124 | .coverage-summary td { border-right: 1px solid #bbb; }
125 | .coverage-summary td:last-child { border-right: none; }
126 | .coverage-summary th {
127 | text-align: left;
128 | font-weight: normal;
129 | white-space: nowrap;
130 | }
131 | .coverage-summary th.file { border-right: none !important; }
132 | .coverage-summary th.pct { }
133 | .coverage-summary th.pic,
134 | .coverage-summary th.abs,
135 | .coverage-summary td.pct,
136 | .coverage-summary td.abs { text-align: right; }
137 | .coverage-summary td.file { white-space: nowrap; }
138 | .coverage-summary td.pic { min-width: 120px !important; }
139 | .coverage-summary tfoot td { }
140 |
141 | .coverage-summary .sorter {
142 | height: 10px;
143 | width: 7px;
144 | display: inline-block;
145 | margin-left: 0.5em;
146 | background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
147 | }
148 | .coverage-summary .sorted .sorter {
149 | background-position: 0 -20px;
150 | }
151 | .coverage-summary .sorted-desc .sorter {
152 | background-position: 0 -10px;
153 | }
154 | .status-line { height: 10px; }
155 | /* dark red */
156 | .red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
157 | .low .chart { border:1px solid #C21F39 }
158 | /* medium red */
159 | .cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
160 | /* light red */
161 | .low, .cline-no { background:#FCE1E5 }
162 | /* light green */
163 | .high, .cline-yes { background:rgb(230,245,208) }
164 | /* medium green */
165 | .cstat-yes { background:rgb(161,215,106) }
166 | /* dark green */
167 | .status-line.high, .high .cover-fill { background:rgb(77,146,33) }
168 | .high .chart { border:1px solid rgb(77,146,33) }
169 | /* dark yellow (gold) */
170 | .medium .chart { border:1px solid #f9cd0b; }
171 | .status-line.medium, .medium .cover-fill { background: #f9cd0b; }
172 | /* light yellow */
173 | .medium { background: #fff4c2; }
174 | /* light gray */
175 | span.cline-neutral { background: #eaeaea; }
176 |
177 | .cbranch-no { background: yellow !important; color: #111; }
178 |
179 | .cstat-skip { background: #ddd; color: #111; }
180 | .fstat-skip { background: #ddd; color: #111 !important; }
181 | .cbranch-skip { background: #ddd !important; color: #111; }
182 |
183 |
184 | .cover-fill, .cover-empty {
185 | display:inline-block;
186 | height: 12px;
187 | }
188 | .chart {
189 | line-height: 0;
190 | }
191 | .cover-empty {
192 | background: white;
193 | }
194 | .cover-full {
195 | border-right: none !important;
196 | }
197 | pre.prettyprint {
198 | border: none !important;
199 | padding: 0 !important;
200 | margin: 0 !important;
201 | }
202 | .com { color: #999 !important; }
203 | .ignore-none { color: #999; font-weight: normal; }
204 |
205 | .wrapper {
206 | min-height: 100%;
207 | height: auto !important;
208 | height: 100%;
209 | margin: 0 auto -48px;
210 | }
211 | .footer, .push {
212 | height: 48px;
213 | }
214 |
--------------------------------------------------------------------------------
/coverage/lcov-report/endow/cjs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Code coverage report for endow/cjs/
5 |
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
19 | all files endow/cjs/
20 |
21 |
22 |
23 | 100%
24 | Statements
25 | 24/24
26 |
27 |
28 | 100%
29 | Branches
30 | 6/6
31 |
32 |
33 | 100%
34 | Functions
35 | 6/6
36 |
37 |
38 | 100%
39 | Lines
40 | 24/24
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | File
50 |
51 | Statements
52 |
53 | Branches
54 |
55 | Functions
56 |
57 | Lines
58 |
59 |
60 |
61 |
62 | index.js
63 |
64 | 100%
65 | 24/24
66 | 100%
67 | 6/6
68 | 100%
69 | 6/6
70 | 100%
71 | 24/24
72 |
73 |
74 |
75 |
76 |
77 |
78 |
82 |
83 |
84 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/coverage/lcov-report/endow/cjs/index.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Code coverage report for endow/cjs/index.js
5 |
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
21 |
22 |
23 | 100%
24 | Statements
25 | 24/24
26 |
27 |
28 | 100%
29 | Branches
30 | 6/6
31 |
32 |
33 | 100%
34 | Functions
35 | 6/6
36 |
37 |
38 | 100%
39 | Lines
40 | 24/24
41 |
42 |
43 |
44 |
45 |
46 | 1
47 | 2
48 | 3
49 | 4
50 | 5
51 | 6
52 | 7
53 | 8
54 | 9
55 | 10
56 | 11
57 | 12
58 | 13
59 | 14
60 | 15
61 | 16
62 | 17
63 | 18
64 | 19
65 | 20
66 | 21
67 | 22
68 | 23
69 | 24
70 | 25
71 | 26
72 | 27
73 | 28
74 | 29
75 | 30
76 | 31
77 | 32
78 | 33
79 | 34
80 | 35
81 | 36
82 | 37
83 | 38
84 | 39
85 | 40
86 | 41
87 | 42
88 | 43
89 | 44
90 | 45
91 | 46
92 | 47
93 | 48
94 | 49
95 | 50
96 | 51
97 | 52
98 | 53
99 | 54
100 | 55
101 | 56
102 | 57
103 | 58
104 | 59
105 | 60
106 | 61
107 | 62
108 | 63
109 | 64
110 | 65
111 | 66
112 | 67
113 | 68
114 | 69
115 | 70
116 | 71
117 | 72
118 | 73
119 | 74
120 | 75
121 | 76
122 | 77
123 | 78
124 | 79
125 | 80
126 |
127 |
128 |
129 |
130 | 2×
131 |
132 |
133 |
134 |
135 | 2×
136 |
137 |
138 |
139 | 2×
140 |
141 |
142 | 7×
143 |
144 |
145 |
146 |
147 | 2×
148 | 1×
149 | 5×
150 |
151 |
152 | 5×
153 |
154 |
155 |
156 |
157 | 7×
158 | 7×
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 | 7×
176 | 3×
177 | 4×
178 | 3×
179 |
180 |
181 | 5×
182 |
183 |
184 |
185 | 2×
186 |
187 |
188 |
189 | 1×
190 | 3×
191 | 3×
192 | 3×
193 |
194 |
195 |
196 | 1×
197 | 11×
198 |
199 |
200 |
201 | 1×
202 | 13×
203 |
204 | 'use strict';
205 | /*! (c) Andrea Giammarchi, @WebReflection (ISC) */
206 | // inspired by https://github.com/justinfagnani/mixwith.js#mixwith
207 |
208 | // If not available, Symbol could even be a special `String` here
209 | var classes = Symbol('endow');
210 |
211 | // fallback to same symbol, ignore hasInstance completely
212 | // in this case code will be transpiled and the result
213 | // of every instanceof will be simply false
214 | var hasInstance = Symbol.hasInstance || classes;
215 |
216 | // Symbol.hasInstance descriptor is always the same
217 | // no need to pollute GC with useless garbage
218 | var descriptor = {
219 | configurable: true,
220 | value: function (object) {
221 | return this[classes].some(instanceOf, object);
222 | }
223 | };
224 |
225 | // endow can be imported as default or as {endow}
226 | Object.defineProperty(exports, '__esModule', {value: true}).default = endow;
227 | function endow(Super) {
228 | return {
229 | // IE < 9 might throw with code that uses `{with: ...}`
230 | "with": function () {
231 | for (var
232 | Mixin,
233 | Class = Super,
234 | i = 0, length = arguments.length; i < length; i++
235 | ) {
236 | Mixin = arguments[i];
237 | Class = Mixin(Class);
238 | // A Mixin knows all classes it extended.
239 | // there is no iterable WeakSet to do this,
240 | // so derived classes are retained once.
241 | // This should not be a real-world issue
242 | // because classes are usually a pre-defined,
243 | // well known, amount.
244 | // If you create a lot of classes on the fly though,
245 | // and you'd like to use endow, be sure you drain
246 | // that Mixin list from time to time.
247 | //
248 | // Object.getOwnPropertySymbols(Mixin)
249 | // .some(s => /\bendow\b/.test(String(s)) && Mixin[s].splice(0));
250 | //
251 | // Please note after that instanceof operations won't be reliable.
252 | // If you create a lot of classes on the fly though, most likely
253 | // you won't ever need instanceof against Mixins.
254 | if (has(Mixin, classes)) {
255 | Mixin[classes].push(Class);
256 | } else if (!has(Mixin, hasInstance)) {
257 | define(Mixin, Class, {});
258 | }
259 | }
260 | return Class;
261 | }
262 | };
263 | }
264 | exports.endow = endow
265 |
266 | // order matters. In case of a fallback to same symbol
267 | // the Symbol.hasInstance is ignored/overwritten
268 | function define(Mixin, Class, descriptors) {
269 | descriptors[hasInstance] = descriptor;
270 | descriptors[classes] = {value: [Class]};
271 | Object.defineProperties(Mixin, descriptors);
272 | }
273 |
274 | // minifier friendly shortcut
275 | function has(object, value) {
276 | return object.hasOwnProperty(value);
277 | }
278 |
279 | // handy array.some(...) helper
280 | function instanceOf(Class) {
281 | return this instanceof Class;
282 | }
283 |
284 |
285 |
286 |
287 |
291 |
292 |
293 |
300 |
301 |
302 |
303 |
--------------------------------------------------------------------------------
/coverage/lcov-report/endow/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Code coverage report for endow/
5 |
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
21 |
22 |
23 | 100%
24 | Statements
25 | 17/17
26 |
27 |
28 | 100%
29 | Branches
30 | 0/0
31 |
32 |
33 | 100%
34 | Functions
35 | 2/2
36 |
37 |
38 | 100%
39 | Lines
40 | 13/13
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | File
50 |
51 | Statements
52 |
53 | Branches
54 |
55 | Functions
56 |
57 | Lines
58 |
59 |
60 |
61 |
62 | test.js
63 |
64 | 100%
65 | 17/17
66 | 100%
67 | 0/0
68 | 100%
69 | 2/2
70 | 100%
71 | 13/13
72 |
73 |
74 |
75 |
76 |
77 |
78 |
82 |
83 |
84 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/coverage/lcov-report/endow/test.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Code coverage report for endow/test.js
5 |
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
21 |
22 |
23 | 100%
24 | Statements
25 | 17/17
26 |
27 |
28 | 100%
29 | Branches
30 | 0/0
31 |
32 |
33 | 100%
34 | Functions
35 | 2/2
36 |
37 |
38 | 100%
39 | Lines
40 | 13/13
41 |
42 |
43 |
44 |
45 |
46 | 1
47 | 2
48 | 3
49 | 4
50 | 5
51 | 6
52 | 7
53 | 8
54 | 9
55 | 10
56 | 11
57 | 12
58 | 13
59 | 14
60 | 15
61 | 16
62 | 17
63 | 18
64 | 19
65 | 20
66 | 21
67 | 22
68 | 23
69 | 24
70 | 25
71 | 26
72 | 27
73 | 28
74 | 29
75 | 30
76 | 31
77 | 32
78 | 33
79 | 34
80 | 35
81 | 36
82 | 37
83 | 38
84 | 39
85 | 40
86 | 41
87 | 42
88 | 43
89 | 44
90 | 45 1×
91 |
92 | 3×
93 | 2×
94 |
95 |
96 |
97 |
98 |
99 | 1×
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 | 1×
112 | 1×
113 |
114 |
115 | 1×
116 |
117 |
118 |
119 |
120 |
121 | 1×
122 | 1×
123 | 1×
124 |
125 | 1×
126 | 1×
127 |
128 |
129 |
130 | 1×
131 |
132 |
133 |
134 | const {endow} = require('./cjs');
135 |
136 | const M1 = Super => class M1 extends Super {};
137 | const M2 = Super => class M2 extends Super {};
138 | class A {}
139 | class B extends endow(A).with(M1) {}
140 | class C extends endow(A).with(M2) {}
141 | class D extends endow(A).with(M1, M2) {}
142 |
143 | console.assert([
144 | new B instanceof A,
145 | new B instanceof M1,
146 | new C instanceof A,
147 | new C instanceof M2,
148 | new D instanceof A,
149 | new D instanceof M1,
150 | new D instanceof M2,
151 | !(new B instanceof M2),
152 | !(new C instanceof M1)
153 | ].every(Boolean));
154 |
155 | const M3 = Super => class M3 extends Super {};
156 | Object.defineProperty(M3, Symbol.hasInstance, {value() { return false; }});
157 | class Z extends endow(A).with(M1, M3) {}
158 |
159 | console.assert([
160 | new Z instanceof A,
161 | new Z instanceof M1,
162 | !(new Z instanceof M3)
163 | ].every(Boolean));
164 |
165 | delete require.cache[require.resolve('./cjs')];
166 | global.Symbol = String;
167 | const {endow:ish} = require('./cjs');
168 |
169 | const M4 = function (Super) {
170 | return class M4 extends Super {};
171 | };
172 | class E extends ish(A).with(M4) {}
173 |
174 | console.assert([
175 | new E instanceof A,
176 | !(new E instanceof M4)
177 | ].every(Boolean));
178 |
179 |
180 |
181 |
182 |
186 |
187 |
188 |
195 |
196 |
197 |
198 |
--------------------------------------------------------------------------------
/coverage/lcov-report/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Code coverage report for All files
5 |
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
19 | /
20 |
21 |
22 |
23 | 100%
24 | Statements
25 | 41/41
26 |
27 |
28 | 100%
29 | Branches
30 | 6/6
31 |
32 |
33 | 100%
34 | Functions
35 | 8/8
36 |
37 |
38 | 100%
39 | Lines
40 | 37/37
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | File
50 |
51 | Statements
52 |
53 | Branches
54 |
55 | Functions
56 |
57 | Lines
58 |
59 |
60 |
61 |
62 | endow/
63 |
64 | 100%
65 | 17/17
66 | 100%
67 | 0/0
68 | 100%
69 | 2/2
70 | 100%
71 | 13/13
72 |
73 |
74 |
75 | endow/cjs/
76 |
77 | 100%
78 | 24/24
79 | 100%
80 | 6/6
81 | 100%
82 | 6/6
83 | 100%
84 | 24/24
85 |
86 |
87 |
88 |
89 |
90 |
91 |
95 |
96 |
97 |
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/coverage/lcov-report/prettify.css:
--------------------------------------------------------------------------------
1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
2 |
--------------------------------------------------------------------------------
/coverage/lcov-report/prettify.js:
--------------------------------------------------------------------------------
1 | window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^