# combjs

> Tool for combing JavaScript code.

Latest version **2.0.2** (published 2015-04-06) · 0 weekly downloads

## Install

```sh
npm install combjs
pnpm add combjs
yarn add combjs
bun add combjs
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2015-04-06 |
| First published | 2015-02-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Roman Yakimchuk |
| Maintainers | yakimchuk |
| Keywords | comb, format, codestyle, module, api, cli |

## Links

- npm: https://www.npmjs.com/package/combjs
- Repository: yakimchuk/combjs.rules
- npm.io page: https://npm.io/package/combjs

## Dependencies (2)

- [jshint](https://npm.io/package/jshint.md) =2.6.0
- [esprima](https://npm.io/package/esprima.md) =2.0.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2015-04-06
- 2.0.1 — 2015-04-06
- 1.0.53 — 2015-02-08

## README

# CombJS
Tool for combing JavaScript code.

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]

## Installation

```bash
$ npm install combjs --save
```

## What can that module?

This module can format this code (example):

```javascript

var Stream = require('stream').Stream
    , es = exports
    , through = require('through')
    , from = require('from')
    , duplex = require('duplexer')
    , map = require('map-stream')
    , pause = require('pause-stream')
    , split = require('split')
    , pipeline = require('stream-combiner')
    , immediately = global.setImmediate || process.nextTick;

es.Stream = Stream //re-export Stream from core
es.through = through
es.from = from
es.duplex = duplex
es.map = map
es.pause = pause
es.split = split
es.pipeline = es.connect = es.pipe = pipeline
// merge / concat
//
// combine multiple streams into a single stream.
// will emit end only once

es.concat = //actually this should be called concat
    es.merge = function (/*streams...*/) {
        var toMerge = [].slice.call(arguments)
        var stream = new Stream()
        stream.setMaxListeners(0) // allow adding more than 11 streams
        var endCount = 0
        stream.writable = stream.readable = true

        toMerge.forEach(function (e) {
            e.pipe(stream, {end: false})
            var ended = false
            e.on('end', function () {
                ended = true
                endCount ++
            })
        })
        stream.write = function (data) {
            this.emit('data', data)
        }
        stream.destroy = function () {
            toMerge.forEach(function (e) {
            })
        }
        return stream
    }


```

into:

```javascript

var Stream = require('stream').Stream,
    es = exports,
    through = require('through'),
    from = require('from'),
    duplex = require('duplexer'),
    map = require('map-stream'),
    pause = require('pause-stream'),
    split = require('split'),
    pipeline = require('stream-combiner'),
    immediately = global.setImmediate || process.nextTick;

es.Stream = Stream;

//re-export Stream from core
es.through = through;

es.from = from;
es.duplex = duplex;
es.map = map;
es.pause = pause;
es.split = split;
es.pipeline = es.connect = es.pipe = pipeline;

// merge / concat
//
// combine multiple streams into a single stream.
// will emit end only once
es.concat = //actually this should be called concat
es.merge = function (/*streams...*/) {

    var toMerge = [].slice.call(arguments);

    var stream = new Stream();

    stream.setMaxListeners(0);

    // allow adding more than 11 streams
    var endCount = 0;

    stream.writable = stream.readable = true;

    toMerge.forEach(function (e) {

        e.pipe(stream , {
            end: false
        });

        var ended = false;

        e.on('end' , function () {

            ended = true;
            endCount++;

        });

    });

    stream.write = function (data) {

        this.emit('data' , data);

    };

    stream.destroy = function () {

        toMerge.forEach(function (e) {});

    };

    return stream;

};


```

##API

Module will provide the object with method "comb" for combing of a JavaScript code:

combjs.**comb**(**source** *String*, **rules** *Object*, **progressCallback** *Function*);

Example:

```javascript

// mkdir example && cd example && npm init && npm install combjs --save
 
var combjs = require('combjs'),
    source = 'var a=1,b=2;',
    rules = {
        emptylinesAfterCloseBraces: true,
        emptylinesAfterMultilineExpressions: true,
        emptylinesAfterOpenBraces: true,
        emptylinesAfterVariableDefinitions: true,
        emptylinesBeforeCloseBraces: true,
        emptylinesBeforeComments: true,
        emptylinesBeforeMultilineExpressions: true,
        emptylinesBeforeVariableDefinitions: true,
        indent: 4, // You can define any count of spaces
        keywordsBraces: 'inline', // You can define value 'multiline' if needed
        linebreaksAfterCloseBraces: true,
        linebreaksAfterColon: true,
        linebreaksAfterComma: true,
        linebreaksAfterMultilineComment: true,
        linebreaksAfterOpenBraces: true,
        linebreaksAfterSemicolon: true,
        linebreaksBeforeCloseBraces: true,
        spacesAfterColon: true,
        spacesAfterComma: true,
        spacesAroundBinaryExpressions: [
            '+',
            '-',
            '/',
            '*',
            '%',
            '<',
            '>',
            '<=',
            '>=',
            '==',
            '!=',
            '===',
            '!==',
            '<<',
            '>>',
            '>>>',
            '&',
            '|',
            '^',
            '&&',
            '||',
            '=',
            '*=',
            '/=',
            '%=',
            '+=',
            '-=',
            '<<=',
            '>>=',
            '>>>=',
            '&=',
            '^=',
            '|='
        ],
        spacesBeforeComma: true,
        spacesNearKeywords: true,
        stringQuotes: 'single' // You can define value 'double' if needed
    };

var combed = combjs.comb(source, rules, function (currentProgress, total) {
    console.log('current: ', currentProgress, 'remain: ', total - currentProgress);
});

console.log(combed);
 
// some stuff with formatted code inside variable "combed"...

```

You can see full example here: https://github.com/yakimchuk/combjs/blob/master/example-formatter.js

## Current available configurations

```javascript

var config = {
    emptylinesAfterCloseBraces: true,
    emptylinesAfterMultilineExpressions: true,
    emptylinesAfterOpenBraces: true,
    emptylinesAfterVariableDefinitions: true,
    emptylinesBeforeCloseBraces: true,
    emptylinesBeforeComments: true,
    emptylinesBeforeMultilineExpressions: true,
    emptylinesBeforeVariableDefinitions: true,
    indent: 4, // You can define any count of spaces
    keywordsBraces: 'inline', // You can define value 'multiline' if needed
    linebreaksAfterCloseBraces: true,
    linebreaksAfterColon: true,
    linebreaksAfterComma: true,
    linebreaksAfterMultilineComment: true,
    linebreaksAfterOpenBraces: true,
    linebreaksAfterSemicolon: true,
    linebreaksBeforeCloseBraces: true,
    spacesAfterColon: true,
    spacesAfterComma: true,
    spacesAroundBinaryExpressions: [
        '+',
        '-',
        '/',
        '*',
        '%',
        '<',
        '>',
        '<=',
        '>=',
        '==',
        '!=',
        '===',
        '!==',
        '<<',
        '>>',
        '>>>',
        '&',
        '|',
        '^',
        '&&',
        '||',
        '=',
        '*=',
        '/=',
        '%=',
        '+=',
        '-=',
        '<<=',
        '>>=',
        '>>>=',
        '&=',
        '^=',
        '|='
    ],
    spacesBeforeComma: true,
    spacesNearKeywords: true,
    stringQuotes: 'single' // You can define value 'double' if needed
};

```

## Contribution

I accept any of your changes. Modify the code, and send pull requests to me :)

[npm-image]: https://img.shields.io/npm/v/combjs.svg?style=flat
[npm-url]: https://npmjs.org/package/combjs
[downloads-image]: https://img.shields.io/npm/dm/combjs.svg?style=flat
[downloads-url]: https://npmjs.org/package/combjs

[information-link]: http://combjs.com/install
[cli-link]: http://combjs.com/cli
[rules-link]: https://github.com/yakimchuk/combjs.rules
[utils-link]: https://github.com/yakimchuk/combjs.utils
[demo-link]: http://combjs.com/demo
[documentation-link]: http://combjs.com/doc
[site-link]: http://combjs.com/

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