Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 19, 2019
1 parent 5e98bad commit dc3c6e7
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 94 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
13 changes: 0 additions & 13 deletions .jshintrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
sudo: false
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'
- '10'
- '8'
17 changes: 17 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
Check if a filepath is a text file.
@example
```
import isTextPath = require('is-text-path');
isTextPath('src/unicorn.txt');
//=> true
isTextPath('src/unicorn.png');
//=> false
```
*/
declare function isTextPath(filepath: string): boolean;

export = isTextPath;
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
'use strict';
var path = require('path');
var textExtensions = require('text-extensions');
var exts = Object.create(null);
const path = require('path');
const textExtensions = require('text-extensions');

textExtensions.forEach(function (el) {
exts[el] = true;
});
const extensions = new Set(textExtensions);

module.exports = function (filepath) {
return path.extname(filepath).slice(1).toLowerCase() in exts;
module.exports = filepath => {
return extensions.has(path.extname(filepath).slice(1).toLowerCase());
};
4 changes: 4 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {expectType} from 'tsd';
import isTextPath = require('.');

expectType<boolean>(isTextPath('src/unicorn.txt'));
20 changes: 4 additions & 16 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
77 changes: 40 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
{
"name": "is-text-path",
"version": "1.0.1",
"description": "Check if a filepath is a text file",
"license": "MIT",
"repository": "sindresorhus/is-text-path",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "ava"
},
"files": [
"index.js"
],
"keywords": [
"txt",
"text",
"ext",
"extensions",
"extension",
"file",
"path",
"check",
"detect",
"is"
],
"dependencies": {
"text-extensions": "^1.0.0"
},
"devDependencies": {
"ava": "*"
}
"name": "is-text-path",
"version": "1.0.1",
"description": "Check if a filepath is a text file",
"license": "MIT",
"repository": "sindresorhus/is-text-path",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"txt",
"text",
"ext",
"extensions",
"extension",
"file",
"path",
"check",
"detect",
"is"
],
"dependencies": {
"text-extensions": "^2.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
## Install

```
$ npm install --save is-text-path
$ npm install is-text-path
```


## Usage

```js
var isTextPath = require('is-text-path');
const isTextPath = require('is-text-path');

isTextPath('src/unicorn.txt');
//=> true
Expand All @@ -31,4 +31,4 @@ isTextPath('src/unicorn.png');

## License

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
16 changes: 8 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import test from 'ava';
import m from './';
import isTextPath from '.';

test(t => {
t.true(m('unicorn.txt'));
t.true(m('unicorn.md'));
t.true(m('unicorn.MD'));
t.false(m('unicorn.png'));
t.false(m('unicorn.zip'));
t.false(m('unicornzip'));
test('main', t => {
t.true(isTextPath('unicorn.txt'));
t.true(isTextPath('unicorn.md'));
t.true(isTextPath('unicorn.MD'));
t.false(isTextPath('unicorn.png'));
t.false(isTextPath('unicorn.zip'));
t.false(isTextPath('unicornzip'));
});

0 comments on commit dc3c6e7

Please sign in to comment.