# @brigand/craft-js

> create javascript code programatically

Latest version **0.1.0** (published 2018-05-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @brigand/craft-js
pnpm add @brigand/craft-js
yarn add @brigand/craft-js
bun add @brigand/craft-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2018-05-12 |
| First published | 2018-05-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 154 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Frankie Bagnardi |
| Maintainers | brigand2, greenjello |

## Links

- npm: https://www.npmjs.com/package/@brigand/craft-js
- Repository: https://github.com/brigand/craft-js
- Homepage: https://github.com/brigand/craft-js#readme
- Issues: https://github.com/brigand/craft-js/issues
- npm.io page: https://npm.io/package/@brigand/craft-js

## Dependencies (3)

- [prettier](https://npm.io/package/prettier.md) 1.12.1
- [babel-core](https://npm.io/package/babel-core.md) ^6.26.3
- [babel-generator](https://npm.io/package/babel-generator.md) ^6.26.1

## Recent versions

- 0.1.0 (latest) — 2018-05-12

## README

craft-js aids in creating JavaScript source code programmatically.

## Install

```
yarn add @brigand/craft-js

# or
npm install --save @brigand/craft-js
```

## fromValue

Currently the only API available, `fromValue` allows you to convert a primitive
JS value to either a babel AST node, or JS source code.

```js
const { fromValue } = require('@brigand/craft-js');

const jsCode = fromValue({ x: 1, y: [2, 3] }).toJs();
console.log(jsCode);
```

This program produces the following output:

```
{
  x: 1,
  y: [2, 3]
}
```

To get at the inner value (a babel AST node in this case) you can call
`.unwrap()`.

```js
const node = fromValue({ x: 1, y: [2, 3] }).unwrap();
node; /* =>
{ type: 'ObjectExpression',
  properties:
   [ { type: 'ObjectProperty',
       key: { type: 'Identifier', name: 'x' },
       value: { type: 'NumericLiteral', value: 1 },
       computed: false,
       shorthand: false,
       decorators: null },
     { type: 'ObjectProperty',
       key: { type: 'Identifier', name: 'y' },
       value:
        { type: 'ArrayExpression',
          elements:
           [ { type: 'NumericLiteral', value: 2 },
             { type: 'NumericLiteral', value: 3 } ] },
       computed: false,
       shorthand: false,
       decorators: null } ] }
*/
```

---
_Source: https://npm.io/package/@brigand/craft-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
