-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 8, use
undefined
instead of null
, add TypeScript …
…definition (#25)
- Loading branch information
1 parent
b45b213
commit 7cd7e43
Showing
8 changed files
with
122 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
declare namespace detectIndent { | ||
interface Indent { | ||
/** | ||
Type of indentation. Is `undefined` if no indentation is detected. | ||
*/ | ||
type: 'tab' | 'space' | undefined; | ||
|
||
/** | ||
Amount of indentation, for example `2`. | ||
*/ | ||
amount: number; | ||
|
||
/** | ||
Actual indentation. | ||
*/ | ||
indent: string; | ||
} | ||
} | ||
|
||
/** | ||
Detect the indentation of code. | ||
@param string - A string of any kind of text. | ||
@example | ||
``` | ||
import * as fs from 'fs'; | ||
import detectIndent = require('detect-indent'); | ||
// { | ||
// "ilove": "pizza" | ||
// } | ||
const file = fs.readFileSync('foo.json', 'utf8'); | ||
// Tries to detect the indentation and falls back to a default if it can't | ||
const indent = detectIndent(file).indent || ' '; | ||
const json = JSON.parse(file); | ||
json.ilove = 'unicorns'; | ||
fs.writeFileSync('foo.json', JSON.stringify(json, null, indent)); | ||
// { | ||
// "ilove": "unicorns" | ||
// } | ||
``` | ||
*/ | ||
declare function detectIndent(string: string): detectIndent.Indent; | ||
|
||
export = detectIndent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {expectType} from 'tsd'; | ||
import detectIndent = require('.'); | ||
|
||
const indent = detectIndent(''); | ||
expectType<detectIndent.Indent>(indent); | ||
expectType<number>(indent.amount); | ||
expectType<string>(indent.indent); | ||
expectType<'space' | 'tab' | undefined>(indent.type); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters