How to make an iterator out of an ES6 class

You need to specify Symbol.iterator property for SomeClass which returns iterator for class instances. Iterator must have next() method, witch in turn returns object with done and value fields. Simplified example: function SomeClass() { this._data = [1,2,3,4]; } SomeClass.prototype[Symbol.iterator] = function() { var index = 0; var data = this._data; return { next: function() { … Read more

ES2015 “import” not working in node v6.0.0 with with –harmony_modules option

They’re just not implemented yet. Node 6.0.0 uses a version of V8 with most of ES6 features completed. Unfortunately modules isn’t one of those completed features. node –v8-options | grep harmony in progress harmony flags are not fully implemented and usually are not working: –es_staging (enable test-worthy harmony features (for internal use only)) –harmony (enable … Read more

How to delete property from spread operator?

You could use Rest syntax in Object Destructuring to get all the properties except drugName to a rest variable like this: const transformedResponse = [{ drugName: ‘HYDROCODONE-HOMATROPINE MBR’, drugStrength: ‘5MG-1.5MG’, drugForm: ‘TABLET’, brand: false }, { drugName: ‘HYDROCODONE ABC’, drugStrength: ’10MG’, drugForm: ‘SYRUP’, brand: true }] const output = transformedResponse.map(({ drugName, …rest }) => rest) … Read more

How can I unit test non-exported functions?

Export an “exportedForTesting” const function shouldntBeExportedFn(){ // Does stuff that needs to be tested // but is not for use outside of this package } export function exportedFn(){ // A function that should be called // from code outside of this package and // uses other functions in this package } export const exportedForTesting = … Read more

eslint object-shorthand error with variable passed in

An excerpt from eslint regarding the issue: Require Object Literal Shorthand Syntax (object-shorthand) – Rule Details This rule enforces the use of the shorthand syntax. This applies to all methods (including generators) defined in object literals and any properties defined where the key name matches name of the assigned variable. Change closeOnSelect: closeOnSelect to just … Read more

SyntaxError: ‘import’ and ‘export’ may appear only with ‘sourceType: module’ – Gulp

Older versions of Babel came with everything out of the box. The newer version requires you install whichever plugins your setup needs. First, you’ll need to install the ES2015 preset. npm install babel-preset-es2015 –save-dev Next, you need to tell babelify to use the preset you installed. return browserify({ … }) .transform(babelify.configure({ presets: [“es2015”] })) … … Read more