Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 5, 2019
1 parent f6f5578 commit 96ab233
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
31 changes: 24 additions & 7 deletions index.d.ts
@@ -1,9 +1,26 @@
/// <reference types="node"/>

/**
* Check if a string or buffer is [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics).
*
* @param input - The data to check.
* @returns Whether `input` is SVG or not.
*/
export default function isSvg(input: string | Buffer): boolean;
declare const isSvg: {
/**
Check if a string or buffer is [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics).
@param input - The data to check.
@returns Whether `input` is SVG or not.
@example
```
import isSvg = require('is-svg');
isSvg('<svg xmlns="http://www.w3.org/2000/svg"><path fill="#00CD9F"/></svg>');
//=> true
```
*/
(input: string | Buffer): boolean;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function isSvg(input: string | Buffer): boolean;
// export = isSvg;
default: typeof isSvg;
};

export = isSvg;
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -20,4 +20,5 @@ const regex = /^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:\[?(?:\s*<![^>
const isSvg = input => Boolean(input) && !isBinary(input) && regex.test(input.toString().replace(htmlCommentRegex, ''));

module.exports = isSvg;
// TODO: Remove this for the next major release
module.exports.default = isSvg;
4 changes: 2 additions & 2 deletions index.test-d.ts
@@ -1,5 +1,5 @@
import {expectType} from 'tsd-check';
import isSvg from '.';
import {expectType} from 'tsd';
import isSvg = require('.');

const data = '<svg></svg>';

Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -36,12 +36,12 @@
"buffer"
],
"dependencies": {
"html-comment-regex": "^1.1.0"
"html-comment-regex": "^1.1.2"
},
"devDependencies": {
"@types/node": "^11.10.4",
"ava": "^1.2.1",
"tsd-check": "^0.3.0",
"@types/node": "^11.13.0",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit 96ab233

Please sign in to comment.