Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

detab

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detab - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

91

index.js

@@ -0,17 +1,22 @@

/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module detab
* @fileoverview Detab: tabs -> spaces.
*/
'use strict';
/*
* Dependencies.
*/
/* Expose. */
module.exports = detab;
/* Dependencies. */
var repeat = require('repeat-string');
/*
* Constants.
*/
/* Constants. */
var TAB = 0x09;
var LF = 0x0a;
var CR = 0x0d;
var TAB = '\t';
var NEWLINE = '\n';
var SPACE = ' ';
/**

@@ -21,7 +26,2 @@ * Replace tabs with spaces, being smart about which

*
* @example
* detab('\tfoo\nbar\tbaz'); // ' foo\nbar baz'
* detab('\tfoo\nbar\tbaz', 2); // ' foo\nbar baz'
* detab('\tfoo\nbar\tbaz', 8); // ' foo\nbar baz'
*
* @param {string} value - Value with tabs.

@@ -32,41 +32,34 @@ * @param {number?} [size=4] - Tab-size.

function detab(value, size) {
var string = typeof value === 'string';
var length = string && value.length;
var index = -1;
var column = -1;
var tabSize = size || 4;
var result = '';
var character;
var add;
var string = typeof value === 'string';
var length = string && value.length;
var start = 0;
var index = -1;
var column = -1;
var tabSize = size || 4;
var results = [];
var code;
var add;
if (!string) {
throw new Error('detab expected string');
}
if (!string) {
throw new Error('detab expected string');
}
while (++index < length) {
character = value.charAt(index);
while (++index < length) {
code = value.charCodeAt(index);
if (character === TAB) {
add = tabSize - ((column + 1) % tabSize);
result += repeat(SPACE, add);
column += add;
continue;
}
if (code === TAB) {
add = tabSize - ((column + 1) % tabSize);
column += add;
results.push(value.slice(start, index) + repeat(' ', add));
start = index + 1;
} else if (code === LF || code === CR) {
column = -1;
} else {
column++;
}
}
if (character === NEWLINE) {
column = -1;
} else {
column++;
}
results.push(value.slice(start));
result += character;
}
return result;
return results.join('');
}
/*
* Expose.
*/
module.exports = detab;
{
"name": "detab",
"version": "1.0.2",
"version": "2.0.0",
"description": "Detab: tabs -> spaces",

@@ -13,44 +13,57 @@ "license": "MIT",

],
"files": [
"index.js"
],
"dependencies": {
"repeat-string": "^1.5.2"
"repeat-string": "^1.5.4"
},
"files": [
"index.js",
"LICENSE"
"repository": "https://github.com/wooorm/detab",
"bugs": "https://github.com/wooorm/detab/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
],
"repository": {
"type": "git",
"url": "https://github.com/wooorm/detab.git"
},
"author": "Titus Wormer <tituswormer@gmail.com>",
"devDependencies": {
"browserify": "^10.0.0",
"eslint": "^0.24.0",
"esmangle": "^1.0.0",
"istanbul": "^0.3.0",
"jscs": "^1.0.0",
"jscs-jsdoc": "^1.0.0",
"mdast": "^0.26.0",
"mdast-github": "^0.3.1",
"mdast-lint": "^0.4.1",
"mdast-usage": "^0.3.0",
"mdast-yaml-config": "^0.2.0",
"mocha": "^2.0.0"
"browserify": "^13.0.1",
"esmangle": "^1.0.1",
"nyc": "^7.0.0",
"remark-cli": "^1.0.0",
"remark-comment-config": "^4.0.0",
"remark-github": "^5.0.0",
"remark-lint": "^4.0.0",
"remark-validate-links": "^4.0.0",
"tape": "^4.0.0",
"xo": "^0.16.0"
},
"scripts": {
"test-api": "mocha --check-leaks test.js",
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test.js",
"test-coverage": "istanbul cover _mocha -- --check-leaks test.js",
"test-travis": "npm run test-coveralls",
"test": "npm run test-api",
"lint-api": "eslint .",
"lint-style": "jscs --reporter inline .",
"lint": "npm run lint-api && npm run lint-style",
"make": "npm run lint && npm run test-coverage",
"build-md": "mdast . LICENSE --output --quiet",
"build-md": "remark . --quiet --frail",
"build-bundle": "browserify index.js --bare -s detab > detab.js",
"postbuild-bundle": "esmangle detab.js > detab.min.js",
"build": "npm run build-md && npm run build-bundle",
"prepublish": "npm run build"
"build-mangle": "esmangle detab.js > detab.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
},
"xo": {
"space": true,
"ignores": [
"detab.js",
"detab.min.js"
]
},
"remarkConfig": {
"output": true,
"plugins": {
"comment-config": null,
"github": null,
"lint": {
"heading-increment": false
},
"validate-links": null
},
"settings": {
"bullet": "*"
}
}
}

@@ -1,2 +0,2 @@

# detab [![Build Status](https://img.shields.io/travis/wooorm/detab.svg?style=flat)](https://travis-ci.org/wooorm/detab) [![Coverage Status](https://img.shields.io/coveralls/wooorm/detab.svg?style=flat)](https://coveralls.io/r/wooorm/detab?branch=master)
# detab [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]

@@ -7,3 +7,3 @@ Detab: tabs -> spaces.

[npm](https://docs.npmjs.com/cli/install):
[npm][npm-install]:

@@ -14,7 +14,2 @@ ```bash

**detab** is also available for [bower](http://bower.io/#install-packages),
[component](https://github.com/componentjs/component), [duo](http://duojs.org/#getting-started),
and for AMD, CommonJS, and globals ([uncompressed](detab.js) and
[compressed](detab.min.js)).
## Usage

@@ -28,3 +23,3 @@

Create a normal error and format a string:
Detab:

@@ -56,3 +51,3 @@ ```javascript

### detab(value\[, size\])
### `detab(value[, size=4])`

@@ -62,3 +57,3 @@ Replace tabs with spaces, being smart about which column the tab is at

Parameters:
###### Parameters

@@ -68,6 +63,24 @@ * `value` (`string`) — Value with tabs;

Returns: `string` — Value without tabs
###### Returns
`string` — Value without tabs
## License
[MIT](LICENSE) @ [Titus Wormer](http://wooorm.com)
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[travis-badge]: https://img.shields.io/travis/wooorm/detab.svg
[travis]: https://travis-ci.org/wooorm/detab
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/detab.svg
[codecov]: https://codecov.io/github/wooorm/detab
[npm-install]: https://docs.npmjs.com/cli/install
[license]: LICENSE
[author]: http://wooorm.com

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc