1
1
# Mixins
2
2
3
- [ ![ version] ( https://img.shields.io/badge/release-v0.4.0-success )] ( https://github.com/udibo/mixins/tree/v0.4.0 )
3
+ [ ![ version] ( https://img.shields.io/badge/release-v0.5.0-success )] ( https://github.com/udibo/mixins/tree/v0.5.0 )
4
+ [ ![ deno doc
] ( https://img.shields.io/badge/deno-doc-success?logo=deno )] ( https://doc.deno.land/https/deno.land/x/[email protected] /mod.ts )
5
+ [ ![ deno version] ( https://img.shields.io/badge/deno-v1.3.2-success?logo=deno )] ( https://github.com/denoland/deno/tree/v1.3.2 )
4
6
[ ![ CI] ( https://github.com/udibo/mixins/workflows/CI/badge.svg )] ( https://github.com/udibo/mixins/actions?query=workflow%3ACI )
5
- [ ![ deno version] ( https://img.shields.io/badge/deno-v1.2.2-success )] ( https://github.com/denoland/deno/tree/v1.2.2 )
6
- [ ![ deno doc] ( https://doc.deno.land/badge.svg )] ( https://doc.deno.land/https/raw.githubusercontent.com/udibo/mixins/v0.4.0/mod.ts )
7
7
[ ![ license] ( https://img.shields.io/github/license/udibo/mixins )] ( https://github.com/udibo/mixins/blob/master/LICENSE )
8
8
9
9
This module provides a few basic functions to help combine objects or build up classes from partial classes.
10
10
11
+ ## Features
12
+
13
+ - Apply mixins to objects, functions, or classes.
14
+
15
+ ## Installation
16
+
17
+ This is an ES Module written in TypeScript and can be used in Deno projects. ES Modules are the official standard format to package JavaScript code for reuse. A JavaScript bundle is provided with each release so that it can be used in Node.js packages or web browsers.
18
+
19
+ ### Deno
20
+
21
+ To include it in a Deno project, you can import directly from the TS files.
22
+ This module is available in Deno's third part module registry
23
+ but can also be imported directly from GitHub using raw content URLs.
24
+
25
+ ``` ts
26
+ // Import from Deno's third party module registry
27
+ import {
applyMixins }
from " https://deno.land/x/[email protected] /mod.ts" ;
28
+ // Import from GitHub
29
+ import { applyMixins } " https://raw.githubusercontent.com/udibo/mixins/v0.5.0/mod.ts" ;
30
+ ` ` `
31
+
32
+ ### Node.js
33
+
34
+ Node.js fully supports ES Modules.
35
+
36
+ If a Node.js package has the type "module" specified in its package.json file, the JavaScript bundle can be imported as a ` .js ` file.
37
+
38
+ ` ` ` js
39
+ import { applyMixins } from " ./mixins_v0.5.0.js" ;
40
+ ```
41
+
42
+ The default type for Node.js packages is "commonjs".
43
+ To import the bundle into a commonjs package, the file extension of the JavaScript bundle must be changed from ` .js ` to ` .mjs ` .
44
+
45
+ ``` js
46
+ import { applyMixins } from " ./mixins_v0.5.0.mjs" ;
47
+ ```
48
+
49
+ See [ Node.js Documentation] ( https://nodejs.org/api/esm.html ) for more information.
50
+
51
+ ### Browser
52
+
53
+ Most modern browsers support ES Modules.
54
+
55
+ The JavaScript bundle can be imported into ES modules.
56
+ Script tags for ES modules must have the type attribute set to "module".
57
+
58
+ ``` html
59
+ <script type =" module" src =" main.js" ></script >
60
+ ```
61
+
62
+ ``` js
63
+ // main.js
64
+ import { applyMixins } from " ./mixins_v0.5.0.js" ;
65
+ ```
66
+
67
+ You can also embed a module script directly into an HTML file by placing the JavaScript code
68
+ within the body of the script tag.
69
+
70
+ ``` html
71
+ <script type =" module" >
72
+ import { applyMixins } from " ./mixins_v0.5.0.js" ;
73
+ </script >
74
+ ```
75
+
76
+ See [ MDN Documentation] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules ) for more information.
77
+
11
78
## Usage
12
79
13
- ` apply.ts ` module provides 3 methods for mixing objects and classes together .
80
+ Below are some examples of how to use each of the functions provided by the mixins module .
14
81
15
82
### applyMixins
16
83
@@ -19,7 +86,7 @@ Applies properties of mixins to instance.
19
86
Using ` applyMixins ` to add properties to an object:
20
87
21
88
``` ts
22
- import { applyMixins } from " https://raw.githubusercontent.com/udibo /mixins/ v0.4 .0/apply .ts" ;
89
+ import { applyMixins } from " https://deno.land/x /mixins@ v0.5 .0/mod .ts" ;
23
90
interface Point {
24
91
x: number ;
25
92
y: number ;
@@ -41,7 +108,7 @@ point3; // { time: 5, x: 2, y: 3, z: 7 }
41
108
Using ` applyMixins ` to add properties to a function:
42
109
43
110
``` ts
44
- import { applyMixins } from " https://raw.githubusercontent.com/udibo /mixins/ v0.4 .0/apply .ts" ;
111
+ import { applyMixins } from " https://deno.land/x /mixins@ v0.5 .0/mod .ts" ;
45
112
interface Point {
46
113
x: number ;
47
114
y: number ;
@@ -78,7 +145,7 @@ point3.toString(); // "2, 3, 7, 5"
78
145
Using ` applyMixins ` to add properties to a class:
79
146
80
147
``` ts
81
- import { applyMixins } from " https://raw.githubusercontent.com/udibo /mixins/ v0.4 .0/apply .ts" ;
148
+ import { applyMixins } from " https://deno.land/x /mixins@ v0.5 .0/mod .ts" ;
82
149
interface Point {
83
150
x: number ;
84
151
y: number ;
@@ -130,7 +197,7 @@ point3.toString(); // "1, 2, 3, 4"
130
197
Applies properties of base class prototypes to instance.
131
198
132
199
``` ts
133
- import { applyMixins , applyInstanceMixins } from " https://raw.githubusercontent.com/udibo /mixins/ v0.4 .0/apply .ts" ;
200
+ import { applyMixins , applyInstanceMixins } from " https://deno.land/x /mixins@ v0.5 .0/mod .ts" ;
134
201
class Point {
135
202
constructor (public x : number , public y : number ) {}
136
203
@@ -177,7 +244,7 @@ point.toString(); // "2, 3, 7, 5"
177
244
Applies properties of base class prototypes to class prototype.
178
245
179
246
``` ts
180
- import { applyMixins , applyClassMixins } from " https://raw.githubusercontent.com/udibo /mixins/ v0.4 .0/apply .ts" ;
247
+ import { applyMixins , applyClassMixins } from " https://deno.land/x /mixins@ v0.5 .0/mod .ts" ;
181
248
class Point {
182
249
constructor (public x : number , public y : number ) {}
183
250
0 commit comments