Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 12, 2019
1 parent 2c1efd5 commit c4847a7
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* 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
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- '6'
- '4'
- '10'
- '8'
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Check if a string is a [scoped npm package name](https://docs.npmjs.com/misc/scope).
*
* @param input - The package name to check.
*/
export default function isScoped(input: string): boolean;
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';
const scopedRegex = require('scoped-regex');

module.exports = input => scopedRegex({exact: true}).test(input);
const isScoped = input => scopedRegex({exact: true}).test(input);

module.exports = isScoped;
module.exports.default = isScoped;
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-check';
import isScoped from '.';

expectType<boolean>(isScoped('is-scoped'));
74 changes: 38 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
{
"name": "is-scoped",
"version": "1.0.0",
"description": "Check if a string is a scoped npm package name",
"license": "MIT",
"repository": "sindresorhus/is-scoped",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"scoped",
"npm",
"package",
"name",
"is",
"detect",
"validate",
"validation"
],
"dependencies": {
"scoped-regex": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "is-scoped",
"version": "1.0.0",
"description": "Check if a string is a scoped npm package name",
"license": "MIT",
"repository": "sindresorhus/is-scoped",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"scoped",
"npm",
"package",
"name",
"is",
"detect",
"validate",
"validation"
],
"dependencies": {
"scoped-regex": "^1.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"tsd-check": "^0.3.0",
"xo": "^0.24.0"
}
}
12 changes: 6 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import m from '.';
import isScoped from '.';

const matches = [
'@sindresorhus/df',
Expand All @@ -19,12 +19,12 @@ const nonMatches = [
'@foo89/_bar'
];

test(t => {
for (const x of matches) {
t.true(m(x));
test('isScoped', t => {
for (const match of matches) {
t.true(isScoped(match));
}

for (const x of nonMatches) {
t.false(m(x));
for (const nonMatch of nonMatches) {
t.false(isScoped(nonMatch));
}
});

0 comments on commit c4847a7

Please sign in to comment.