esformatter-dot-notation

esformatter plugin for transforming object bracket usage to dot notation


Keywords
esformatter, esformatter-plugin, string, dot-notation, literal, AST, rocambole, esprima, codestyle
License
MIT
Install
npm install esformatter-dot-notation@1.3.1

Documentation

esformatter-dot-notation

esformatter plugin for transforming object bracket usage to dot notation

NPM Version NPM Downloads Build Status

esformatter-dot-notation is a plugin for esformatter meant to convert accessing object properties with brackets into dot notation where valid.

This module uses unquoted-property-validator which uses Mathias Bynens implementation in order to validate if a property name is a valid identifier name and can be used with dot notation.

That means invalid identifiers will not be converted and your code is safe for transformations (see tests).

Turn this:

someObject['property'] = true;

into:

someObject.property = true;

Installation

$ npm install esformatter-dot-notation --save-dev

Config

Newest esformatter versions autoload plugins from your node_modules See this

Add to your esformatter config file:

{
  "plugins": [
    "esformatter-dot-notation"
  ]
}

Or you can manually register your plugin:

var dotNotation = require('esformatter-dot-notation');
// register plugin
esformatter.register(dotNotation);

Usage

var fs = require('fs');
var esformatter = require('esformatter');
//register plugin manually
esformatter.register(require('esformatter-dot-notation'));

var str = fs.readFileSync('someKewlFile.js').toString();
var output = esformatter.format(str);
//-> output will now contain the formatted string

See esformatter for more options and further usage.

License

MIT @Gilad Peleg