Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 shorthand import

Tags:

Is there a shorter ES6 way of doing:

var assert = require('chai').assert; 

than

import chai from 'chai'; var assert = chai.assert; 

(chai is the chai-assertion library, in case you haven't heard of it yet.)

like image 540
simonzack Avatar asked Feb 17 '15 06:02

simonzack


People also ask

Does ES6 support import?

ES6 modules are automatically strict-mode code, even if you don't write "use strict"; in them. You can use import and export in modules.


1 Answers

Yes, you can do it like:

import { assert } from 'chai'; 

assert must be exporting from chai in that case. See spec here and about es6 modules here

like image 194
alexpods Avatar answered Oct 16 '22 14:10

alexpods