From d29071c1c00047976ba2413b566e5927fed20a20 Mon Sep 17 00:00:00 2001
From: Sindre Sorhus <sindresorhus@gmail.com>
Date: Wed, 1 Mar 2023 03:56:47 +0700
Subject: [PATCH] Require Node.js 14 and move to ESM

---
 index.d.ts      | 36 ++++++++++++------------------------
 index.js        | 25 ++++++++++---------------
 index.test-d.ts |  7 ++-----
 license         |  2 +-
 package.json    | 25 +++++++++++++------------
 readme.md       | 20 ++++----------------
 test.js         | 15 +++++++--------
 7 files changed, 49 insertions(+), 81 deletions(-)

diff --git a/index.d.ts b/index.d.ts
index 611e066..9d7ef35 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,24 +1,12 @@
-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;
+/**
+Check if a string is [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics).
+
+@example
+```
+import isSvg from 'is-svg';
+
+isSvg('<svg xmlns="http://www.w3.org/2000/svg"><path fill="#00CD9F"/></svg>');
+//=> true
+```
+*/
+export default function isSvg(string: string): boolean;
diff --git a/index.js b/index.js
index bfb6d08..54b5562 100644
--- a/index.js
+++ b/index.js
@@ -1,19 +1,18 @@
-'use strict';
-const {XMLParser, XMLValidator} = require('fast-xml-parser');
+import {XMLParser, XMLValidator} from 'fast-xml-parser';
 
-const isSvg = input => {
-	if (input === undefined || input === null) {
-		return false;
+export default function isSvg(string) {
+	if (typeof string !== 'string') {
+		throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
 	}
 
-	input = input.toString().trim();
+	string = string.trim();
 
-	if (input.length === 0) {
+	if (string.length === 0) {
 		return false;
 	}
 
 	// Has to be `!==` as it can also return an object with error info.
-	if (XMLValidator.validate(input) !== true) {
+	if (XMLValidator.validate(string) !== true) {
 		return false;
 	}
 
@@ -21,8 +20,8 @@ const isSvg = input => {
 	const parser = new XMLParser();
 
 	try {
-		jsonObject = parser.parse(input);
-	} catch (_) {
+		jsonObject = parser.parse(string);
+	} catch {
 		return false;
 	}
 
@@ -35,8 +34,4 @@ const isSvg = input => {
 	}
 
 	return true;
-};
-
-module.exports = isSvg;
-// TODO: Remove this for the next major release
-module.exports.default = isSvg;
+}
diff --git a/index.test-d.ts b/index.test-d.ts
index 5484217..4d03816 100644
--- a/index.test-d.ts
+++ b/index.test-d.ts
@@ -1,7 +1,4 @@
 import {expectType} from 'tsd';
-import isSvg = require('.');
+import isSvg from './index.js';
 
-const data = '<svg></svg>';
-
-expectType<boolean>(isSvg(data));
-expectType<boolean>(isSvg(Buffer.from(data)));
+expectType<boolean>(isSvg('<svg></svg>'));
diff --git a/license b/license
index e7af2f7..fa7ceba 100644
--- a/license
+++ b/license
@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://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:
 
diff --git a/package.json b/package.json
index e7410e6..aa59b9d 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
 	"name": "is-svg",
 	"version": "4.4.0",
-	"description": "Check if a string or buffer is SVG",
+	"description": "Check if a string is SVG",
 	"license": "MIT",
 	"repository": "sindresorhus/is-svg",
 	"funding": "https://github.com/sponsors/sindresorhus",
@@ -10,8 +10,13 @@
 		"email": "sindresorhus@gmail.com",
 		"url": "https://sindresorhus.com"
 	},
+	"type": "module",
+	"exports": {
+		"types": "./index.d.ts",
+		"default": "./index.js"
+	},
 	"engines": {
-		"node": ">=6"
+		"node": ">=14.16"
 	},
 	"scripts": {
 		"test": "xo && ava && tsd"
@@ -25,25 +30,21 @@
 		"vector",
 		"graphics",
 		"image",
-		"img",
-		"pic",
 		"picture",
 		"type",
 		"detect",
 		"check",
 		"is",
-		"string",
-		"str",
-		"buffer"
+		"string"
 	],
 	"dependencies": {
 		"fast-xml-parser": "^4.1.3"
 	},
 	"devDependencies": {
-		"@types/node": "^11.13.0",
-		"ava": "^1.4.1",
-		"time-span": "^4.0.0",
-		"tsd": "^0.7.2",
-		"xo": "^0.24.0"
+		"@types/node": "^18.14.2",
+		"ava": "^5.2.0",
+		"time-span": "^5.1.0",
+		"tsd": "^0.25.0",
+		"xo": "^0.53.1"
 	}
 }
diff --git a/readme.md b/readme.md
index 00a3519..f62b06c 100644
--- a/readme.md
+++ b/readme.md
@@ -1,30 +1,18 @@
 # is-svg
 
-> Check if a string or buffer is [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics)
+> Check if a string is [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics)
 
 ## Install
 
-```
-$ npm install is-svg
+```sh
+npm install is-svg
 ```
 
 ## Usage
 
 ```js
-const isSvg = require('is-svg');
+import isSvg from 'is-svg';
 
 isSvg('<svg xmlns="http://www.w3.org/2000/svg"><path fill="#00CD9F"/></svg>');
 //=> true
 ```
-
----
-
-<div align="center">
-	<b>
-		<a href="https://tidelift.com/subscription/pkg/npm-is-svg?utm_source=npm-is-svg&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
-	</b>
-	<br>
-	<sub>
-		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
-	</sub>
-</div>
diff --git a/test.js b/test.js
index 3cca99e..dc73b8f 100644
--- a/test.js
+++ b/test.js
@@ -1,10 +1,10 @@
-import fs from 'fs';
+import fs from 'node:fs';
 import test from 'ava';
 import timeSpan from 'time-span';
-import isSvg from '.';
+import isSvg from './index.js';
 
 test('valid SVGs', t => {
-	t.true(isSvg(fs.readFileSync('fixtures/fixture.svg')));
+	t.true(isSvg(fs.readFileSync('fixtures/fixture.svg', 'utf8')));
 	t.true(isSvg('<svg width="100" height="100" viewBox="0 0 30 30" version="1.1"></svg>'));
 	t.true(isSvg('<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>'));
 	t.true(isSvg('<?xml version="1.0" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg></svg>'));
@@ -30,17 +30,16 @@ version="1.1"
 });
 
 test('invalid SVGs', t => {
-	t.false(isSvg(fs.readFileSync('fixtures/fixture.jpg')));
+	t.false(isSvg(fs.readFileSync('fixtures/fixture.jpg', 'utf8')));
 	t.false(isSvg('<div><svg></svg>'));
 	t.false(isSvg('<div><svg></svg></div>'));
-	t.false(isSvg(fs.readFileSync('index.js')));
-	t.false(isSvg());
+	t.false(isSvg(fs.readFileSync('index.js', 'utf8')));
 	t.false(isSvg('this string contains an svg <svg></svg> in the middle'));
 	t.false(isSvg('<svg><div></svg>'));
 	t.false(isSvg('this string ends with an svg <svg></svg>'));
 	t.false(isSvg('<svg> hello I am an svg oops maybe not'));
 	t.false(isSvg('this is not svg, but it mentions <svg> tags'));
-	t.false(isSvg(fs.readFileSync('readme.md')));
+	t.false(isSvg(fs.readFileSync('readme.md', 'utf8')));
 
 	// https://github.com/NaturalIntelligence/fast-xml-parser/issues/327
 	// t.false(isSvg('<svg></svg> this string starts with an svg'));
@@ -85,7 +84,7 @@ test('support markup inside Entity tags', t => {
 test('regex should not be quadratic', t => {
 	const end = timeSpan();
 
-	isSvg(`<!doctype svg ${' '.repeat(34560)}`);
+	isSvg(`<!doctype svg ${' '.repeat(34_560)}`);
 
 	if (end.seconds() < 10) {
 		t.pass();