# code-this

> Code-this is node.js module that converts JavaScript variables into source codes. Unlike `JSON.stringify`, code-this also deals with reference(object) types of variables.

Latest version **0.1.8** (published 2014-04-16) · BSD license · 0 weekly downloads

## Install

```sh
npm install code-this
pnpm add code-this
yarn add code-this
bun add code-this
```

## 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.8 |
| Published | 2014-04-16 |
| First published | 2013-07-29 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Maintainers | kael |
| Keywords | strinify, json-strinify, codify, code-generator, code |

## Links

- npm: https://www.npmjs.com/package/code-this
- Repository: https://github.com/kaelzhang/node-code-this
- Issues: https://github.com/kaelzhang/node-code-this/issues
- npm.io page: https://npm.io/package/code-this

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.1.8 (latest) — 2014-04-16
- 0.1.7 — 2014-04-16
- 0.1.6 — 2013-10-23
- 0.1.5 — 2013-10-14
- 0.1.4 — 2013-09-26
- 0.1.3 — 2013-08-28
- 0.1.2 — 2013-07-30
- 0.1.1 — 2013-07-29
- 0.1.0 — 2013-07-29

## README

[![NPM version](https://badge.fury.io/js/code-this.png)](http://badge.fury.io/js/code-this)
[![Build Status](https://travis-ci.org/kaelzhang/node-code-this.png?branch=master)](https://travis-ci.org/kaelzhang/node-code-this)
[![Dependency Status](https://gemnasium.com/kaelzhang/node-code-this.png)](https://gemnasium.com/kaelzhang/node-code-this)

# Code-this

Code-this is the node.js module that converts JavaScript variables into source codes. 

Unlike `JSON.stringify`, code-this also deals with reference(object) types of variables.

## Installation

```sh
npm install code-this --save
```

## Usage

```js
var code = require('code-this');
var a = {a: function(n){return n;}, b: 1, c: 3};

code(a, null, 2); // 1
```

Expression {1} will return:

```js
'{\n  \'a\': function (n){return n;},\n  \'b\': 1,\n  \'c\': 3\n}'
```

So you can use code-this to save your javascript variables into a file:

```js
require('fs').writeFileSync(
	'output.js', 
	'module.exports = ' + code(a, null, 2) + ';';
);
```

Then 'output.js' will look like:

```js
module.exports = {
  'a': function (n){return n;},
  'b': 1,
  'c': 3
};
```

## code(subject, replacer, space)

##### subject `mixed`

The subject to be converted

##### replacer `function(key, value)`

The `replacer` argument acts just like the second parameter of `JSON.stringify`.

##### space `number`

The `space` argument acts just like the third parameter of `JSON.stringify`.


## Known Issues

- Code-this can't deal with recursive objects or arrays SO FAR.
- `space` parameter could not affect the code indent inside functions.
- Code-this could not deal with variable scope so far.

Those issues or tasks which should be done to enhance the module might be fixed in the future. Or there will be a million thanks if you fork and contribute ~~

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