-
-
Notifications
You must be signed in to change notification settings - Fork 17
Require Node.js 8, add TypeScript definition #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sindresorhus
merged 3 commits into
sindresorhus:master
from
BendingBender:typescript-defs
Apr 17, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| declare namespace indentString { | ||
| interface Options { | ||
| /** | ||
| String to use for the indent. | ||
|
|
||
| @default ' ' | ||
| */ | ||
| readonly indent?: string; | ||
|
|
||
| /** | ||
| Also indent empty lines. | ||
|
|
||
| @default false | ||
| */ | ||
| readonly includeEmptyLines?: boolean; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| Indent each line in a string. | ||
|
|
||
| @param string - String you want to indent. | ||
| @param count - How many times you want `options.indent` repeated. Default: `1`. | ||
|
|
||
| @example | ||
| ``` | ||
| import indentString = require('indent-string'); | ||
|
|
||
| indentString('Unicorns\nRainbows', 4); | ||
| //=> ' Unicorns' | ||
| //=> ' Rainbows' | ||
|
|
||
| indentString('Unicorns\nRainbows', 4, {indent: '♥'}); | ||
| //=> '♥♥♥♥Unicorns' | ||
| //=> '♥♥♥♥Rainbows' | ||
| ``` | ||
| */ | ||
| declare function indentString( | ||
| string: string, | ||
| count?: number, | ||
| options?: indentString.Options | ||
| ): string; | ||
|
|
||
| export = indentString; |
This file contains hidden or 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,27 +1,35 @@ | ||
| 'use strict'; | ||
| module.exports = (str, count, opts) => { | ||
| // Support older versions: use the third parameter as options.indent | ||
| // TODO: Remove the workaround in the next major version | ||
| const options = typeof opts === 'object' ? Object.assign({indent: ' '}, opts) : {indent: opts || ' '}; | ||
| count = count === undefined ? 1 : count; | ||
|
|
||
| if (typeof str !== 'string') { | ||
| throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof str}\``); | ||
| module.exports = (string, count = 1, options) => { | ||
| options = { | ||
| indent: ' ', | ||
| includeEmptyLines: false, | ||
| ...options | ||
| }; | ||
|
|
||
| if (typeof string !== 'string') { | ||
| throw new TypeError( | ||
| `Expected \`input\` to be a \`string\`, got \`${typeof string}\`` | ||
| ); | ||
| } | ||
|
|
||
| if (typeof count !== 'number') { | ||
| throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``); | ||
| throw new TypeError( | ||
| `Expected \`count\` to be a \`number\`, got \`${typeof count}\`` | ||
| ); | ||
| } | ||
|
|
||
| if (typeof options.indent !== 'string') { | ||
| throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``); | ||
| throw new TypeError( | ||
| `Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\`` | ||
| ); | ||
| } | ||
|
|
||
| if (count === 0) { | ||
| return str; | ||
| return string; | ||
| } | ||
|
|
||
| const regex = options.includeEmptyLines ? /^/mg : /^(?!\s*$)/mg; | ||
| return str.replace(regex, options.indent.repeat(count)); | ||
| } | ||
| ; | ||
| const regex = options.includeEmptyLines ? /^/gm : /^(?!\s*$)/gm; | ||
|
|
||
| return string.replace(regex, options.indent.repeat(count)); | ||
| }; |
This file contains hidden or 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,9 @@ | ||
| import {expectType} from 'tsd'; | ||
| import indentString = require('.'); | ||
|
|
||
| expectType<string>(indentString('Unicorns\nRainbows')); | ||
| expectType<string>(indentString('Unicorns\nRainbows', 4)); | ||
| expectType<string>(indentString('Unicorns\nRainbows', 4, {indent: '♥'})); | ||
| expectType<string>( | ||
| indentString('Unicorns\nRainbows', 4, {includeEmptyLines: true}) | ||
| ); |
This file contains hidden or 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,36 +1,38 @@ | ||
| { | ||
| "name": "indent-string", | ||
| "version": "3.2.0", | ||
| "description": "Indent each line in a string", | ||
| "license": "MIT", | ||
| "repository": "sindresorhus/indent-string", | ||
| "author": { | ||
| "name": "Sindre Sorhus", | ||
| "email": "[email protected]", | ||
| "url": "sindresorhus.com" | ||
| }, | ||
| "engines": { | ||
| "node": ">=4" | ||
| }, | ||
| "scripts": { | ||
| "test": "xo && ava" | ||
| }, | ||
| "files": [ | ||
| "index.js" | ||
| ], | ||
| "keywords": [ | ||
| "indent", | ||
| "string", | ||
| "str", | ||
| "pad", | ||
| "align", | ||
| "line", | ||
| "text", | ||
| "each", | ||
| "every" | ||
| ], | ||
| "devDependencies": { | ||
| "ava": "*", | ||
| "xo": "*" | ||
| } | ||
| "name": "indent-string", | ||
| "version": "3.2.0", | ||
| "description": "Indent each line in a string", | ||
| "license": "MIT", | ||
| "repository": "sindresorhus/indent-string", | ||
| "author": { | ||
| "name": "Sindre Sorhus", | ||
| "email": "[email protected]", | ||
| "url": "sindresorhus.com" | ||
| }, | ||
| "engines": { | ||
| "node": ">=8" | ||
| }, | ||
| "scripts": { | ||
| "test": "xo && ava && tsd" | ||
| }, | ||
| "files": [ | ||
| "index.js", | ||
| "index.d.ts" | ||
| ], | ||
| "keywords": [ | ||
| "indent", | ||
| "string", | ||
| "str", | ||
| "pad", | ||
| "align", | ||
| "line", | ||
| "text", | ||
| "each", | ||
| "every" | ||
| ], | ||
| "devDependencies": { | ||
| "ava": "^1.4.1", | ||
| "tsd": "^0.7.2", | ||
| "xo": "^0.24.0" | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about changing this. Technically,
Objectis correct. It's only TS that has a specialobjecttype. In normal sense, primitives are lowercase and non-primitives pascal-case. Thoughts? I haven't completely made up my mind with this or going with exact TS types.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure either. I saw that you refactored quite a few types to TS notation and thought that you've started using TS types in your docs. So this would be TypeScript's "primitive"
objecttype that accepts any object. TheObjecttype is the object constructor and should not be used for plain objects at least in TS.I don't have a strong preference here, I just wanted to be consistent with TS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Let's go with
object. (See: sindresorhus/meta#1)