https://github.com/passcod/babel-plugin-transform-iota
Transforms iota() calls into ever-increasing literals.
https://github.com/passcod/babel-plugin-transform-iota
Last synced: about 1 month ago
JSON representation
Transforms iota() calls into ever-increasing literals.
- Host: GitHub
- URL: https://github.com/passcod/babel-plugin-transform-iota
- Owner: passcod
- License: isc
- Archived: true
- Created: 2016-02-24T21:48:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-19T02:17:53.000Z (over 7 years ago)
- Last Synced: 2024-11-15T09:44:37.352Z (7 months ago)
- Language: JavaScript
- Homepage: http://npm.im/babel-plugin-transform-iota
- Size: 5.86 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-babel - transform-iota - Golang-style `iota()`. 🔧 (Plugins / Syntax Sugar)
README
# Babel transform: iota
[](https://greenkeeper.io/)
[](https://raw.githubusercontent.com/passcod/babel-plugin-transform-iota/master/LICENSE)
[](https://travis-ci.org/passcod/babel-plugin-transform-iota)
[](http://contributor-covenant.org/version/1/4/)Transforms `iota()` calls into ever-increasing literals, Ã la [Go].
## Installation
```sh
$ npm install babel-plugin-transform-iota
```## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["transform-iota"]
}
```### Via CLI
```sh
$ babel --plugins transform-iota script.js
```### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["transform-iota"]
});
```## Synopsis
**Input**
```js
var foo = iota()
let bar = iota()
bar.baz = iota()
const qux = {
a: iota(),
[iota()]: 'b'
}
```**Output**
```js
var foo = [1]
let bar = [2]
bar.baz = [3]
const qux = {
a: [4],
[[5]]: 'b'
}
```(`[5]` coerces to `"5"`, which becomes a valid key. We cannot directly use
`"5"` as iota, because we want to support the case where we add properties to
an iota, and we can't do that on string literals.)Also removes all functions named `iota()`, so you can still define them and
have a working implementation without Babel (and so your code lints without
`/* global iota */` overrides). Here's a working example:```js
function iota () {
if (!this.i) { this.i = 0 }
return [this.i += 1]
}
```## About
Made by [Félix Saparelli](https://passcod.name).
Licensed under [ISC](https://spdx.org/licenses/ISC.html).
Inspired by [Go].[Go]: https://github.com/golang/go/wiki/Iota