1- import difference from 'lodash/difference' ;
2- import { MIME_TYPE } from './constants' ;
3- import * as properties from './properties' ;
1+ import difference from 'lodash/difference'
2+ import { MIME_TYPE } from './constants'
3+ import * as properties from './properties'
44import {
55 InvalidComponentError ,
66 InvalidProvidedComponentError ,
77 InvalidProvidedPropError
8- } from './errors' ;
8+ } from './errors'
99
1010/**
1111 * Base class for components.
@@ -17,38 +17,38 @@ export default class Component {
1717 * @abstract
1818 * @type {string }
1919 */
20- static componentName = 'Component' ;
20+ static componentName = 'Component'
2121
2222 /**
2323 * String used to separate lines when returning the component as a string.
2424 *
2525 * @type {string }
2626 */
27- static separator = '\r\n' ;
27+ static separator = '\r\n'
2828
2929 /**
3030 * Array of required properties.
3131 *
3232 * @abstract
3333 * @type {string[] }
3434 */
35- static requiredProps = [ ] ;
35+ static requiredProps = [ ]
3636
3737 /**
3838 * Valid properties with appropriate validators.
3939 *
4040 * @abstract
4141 * @type {Object }
4242 */
43- static validProps = { } ;
43+ static validProps = { }
4444
4545 /**
4646 * Valid components with appropriate validators.
4747 *
4848 * @abstract
4949 * @type {Object }
5050 */
51- static validComponents = { } ;
51+ static validComponents = { }
5252
5353 /**
5454 * Create a new component.
@@ -60,31 +60,31 @@ export default class Component {
6060 * @private
6161 * @type {string }
6262 */
63- this . prefix = 'BEGIN:' + this . constructor . componentName ;
63+ this . prefix = 'BEGIN:' + this . constructor . componentName
6464
6565 /**
6666 * Suffix used when returning the component as a string.
6767 *
6868 * @private
6969 * @type {string }
7070 */
71- this . suffix = 'END:' + this . constructor . componentName ;
71+ this . suffix = 'END:' + this . constructor . componentName
7272
7373 /**
7474 * Array to store the component's properties.
7575 *
7676 * @private
7777 * @type {Property[] }
7878 */
79- this . internalProps = [ ] ;
79+ this . internalProps = [ ]
8080
8181 /**
8282 * Array to store the component's components.
8383 *
8484 * @private
8585 * @type {Component[] }
8686 */
87- this . internalComponents = [ ] ;
87+ this . internalComponents = [ ]
8888 }
8989
9090 /**
@@ -93,7 +93,7 @@ export default class Component {
9393 * @returns {Property[] } Frozen array of the component's properties.
9494 */
9595 props ( ) {
96- return Object . freeze ( this . internalProps . slice ( 0 ) ) ;
96+ return Object . freeze ( this . internalProps . slice ( 0 ) )
9797 }
9898
9999 /**
@@ -103,8 +103,8 @@ export default class Component {
103103 */
104104 propNames ( ) {
105105 return Object . freeze ( this . internalProps . map ( ( prop ) => {
106- return prop . constructor . propName ;
107- } ) ) ;
106+ return prop . constructor . propName
107+ } ) )
108108 }
109109
110110 /**
@@ -118,22 +118,22 @@ export default class Component {
118118 * @returns {Property } Configured property instance.
119119 */
120120 addProp ( name , value , props = { } , skipTransformer = false ) {
121- const { validProps} = this . constructor ;
121+ const { validProps} = this . constructor
122122
123123 if ( ! validProps [ name ] ) {
124- throw new InvalidProvidedPropError ( ) ;
124+ throw new InvalidProvidedPropError ( )
125125 }
126126
127- const PropClass = properties [ name ] || properties . base ( name ) ; // eslint-disable-line import/namespace
128- const prop = new PropClass ( value , props , skipTransformer ) ;
127+ const PropClass = properties [ name ] || properties . base ( name )
128+ const prop = new PropClass ( value , props , skipTransformer )
129129
130130 validProps [ name ] . forEach ( ( validator ) => {
131- validator ( this , prop ) ;
132- } ) ;
131+ validator ( this , prop )
132+ } )
133133
134- this . internalProps . push ( prop ) ;
134+ this . internalProps . push ( prop )
135135
136- return prop ;
136+ return prop
137137 }
138138
139139 /**
@@ -142,7 +142,7 @@ export default class Component {
142142 * @returns {Component[] } Frozen array of the component's components.
143143 */
144144 components ( ) {
145- return Object . freeze ( this . internalComponents . slice ( 0 ) ) ;
145+ return Object . freeze ( this . internalComponents . slice ( 0 ) )
146146 }
147147
148148 /**
@@ -152,8 +152,8 @@ export default class Component {
152152 */
153153 componentNames ( ) {
154154 return Object . freeze ( this . internalComponents . map ( ( component ) => {
155- return component . constructor . componentName ;
156- } ) ) ;
155+ return component . constructor . componentName
156+ } ) )
157157 }
158158
159159 /**
@@ -164,31 +164,32 @@ export default class Component {
164164 * @returns {Component } Provided component.
165165 */
166166 addComponent ( component ) {
167- const { validComponents} = this . constructor ;
168- const { componentName} = component . constructor ;
167+ const { validComponents} = this . constructor
168+ const { componentName} = component . constructor
169169
170170 if ( ! ( component instanceof Component ) ) {
171- throw new TypeError ( 'Expected component to be an instance of Component.' ) ;
171+ throw new TypeError ( 'Expected component to be an instance of Component.' )
172172 }
173173
174174 if ( ! validComponents [ componentName ] ) {
175- throw new InvalidProvidedComponentError ( ) ;
175+ throw new InvalidProvidedComponentError ( )
176176 }
177177
178178 validComponents [ componentName ] . forEach ( ( validator ) => {
179- validator ( this , component ) ;
180- } ) ;
179+ validator ( this , component )
180+ } )
181181
182- this . internalComponents . push ( component ) ;
182+ this . internalComponents . push ( component )
183183
184- return component ;
184+ return component
185185 }
186186
187187 /**
188188 * Reset the components components and properties to the default empty state.
189189 */
190190 reset ( ) {
191- this . internalProps = this . internalComponents = [ ] ;
191+ this . internalProps = [ ]
192+ this . internalComponents = [ ]
192193 }
193194
194195 /**
@@ -198,13 +199,13 @@ export default class Component {
198199 * @returns {boolean } All required properties are present.
199200 */
200201 validateRequired ( ) {
201- const { requiredProps} = this . constructor ;
202+ const { requiredProps} = this . constructor
202203
203204 if ( difference ( requiredProps , this . propNames ( ) ) . length > 0 ) {
204- throw new InvalidComponentError ( ) ;
205+ throw new InvalidComponentError ( )
205206 }
206207
207- return true ;
208+ return true
208209 }
209210
210211 /**
@@ -213,22 +214,22 @@ export default class Component {
213214 * @returns {string } String representation of the component.
214215 */
215216 toString ( ) {
216- this . validateRequired ( ) ;
217+ this . validateRequired ( )
217218
218219 const props = this . internalProps . map ( ( prop ) => {
219- return prop . toString ( ) ;
220- } ) ;
220+ return prop . toString ( )
221+ } )
221222
222223 const components = this . internalComponents . map ( ( component ) => {
223- return component . toString ( ) ;
224- } ) ;
224+ return component . toString ( )
225+ } )
225226
226227 return [
227228 this . prefix ,
228229 ...props ,
229230 ...components ,
230231 this . suffix
231- ] . join ( this . constructor . separator ) ;
232+ ] . join ( this . constructor . separator )
232233 }
233234
234235 /**
@@ -238,7 +239,7 @@ export default class Component {
238239 * @returns {Blob } Blob representation of the component.
239240 */
240241 toBlob ( ) {
241- return new Blob ( [ this . toString ( ) ] , { type : MIME_TYPE } ) ;
242+ return new Blob ( [ this . toString ( ) ] , { type : MIME_TYPE } )
242243 }
243244
244245 /**
@@ -248,20 +249,20 @@ export default class Component {
248249 * @returns {Promise<string, DOMError> } Promise that resolves with a Base64 encoded string.
249250 */
250251 toBase64 ( ) {
251- const blob = this . toBlob ( ) ;
252- const reader = new window . FileReader ( ) ;
252+ const blob = this . toBlob ( )
253+ const reader = new window . FileReader ( )
253254
254255 return new Promise ( ( resolve , reject ) => {
255- reader . readAsDataURL ( blob ) ;
256+ reader . readAsDataURL ( blob )
256257 reader . onloadend = ( ) => {
257- resolve ( reader . result ) ;
258- } ;
258+ resolve ( reader . result )
259+ }
259260 reader . onerror = ( ) => {
260- reject ( reader . error ) ;
261- } ;
261+ reject ( reader . error )
262+ }
262263 reader . onabort = ( ) => {
263- reject ( ) ;
264- } ;
265- } ) ;
264+ reject ( )
265+ }
266+ } )
266267 }
267268}
0 commit comments