From 3cf9eacedbe29966ebf9ab54fb8e818714da0d76 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 2 Sep 2021 01:06:29 +0200 Subject: [PATCH] Require Node.js 12.20 and move to ESM --- .github/workflows/main.yml | 7 ++----- index.js | 10 +++++++--- license | 2 +- package.json | 13 ++++++++----- readme.md | 2 +- test.js | 2 +- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..441975c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,13 +10,10 @@ jobs: fail-fast: false matrix: node-version: - - 14 - - 12 - - 10 - - 8 + - 16 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.js b/index.js index f4da4d0..1520bb1 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,11 @@ -'use strict'; -const htmlTags = require('html-tags'); +import htmlTags from 'html-tags'; const basic = /\s?|(]*>|]*>|]+>)+/i; const full = new RegExp(htmlTags.map(tag => `<${tag}\\b[^>]*>`).join('|'), 'i'); -module.exports = string => basic.test(string) || full.test(string); +export default function isHtml(string) { + // We limit it to a reasonable length to improve performance. + string = string.trim().slice(0, 1000); + + return basic.test(string) || full.test(string); +} 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.com) +Copyright (c) Sindre Sorhus (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 84121e7..b4f98e4 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,16 @@ "description": "Check if a string is HTML", "license": "MIT", "repository": "sindresorhus/is-html", + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { "test": "xo && ava" @@ -28,10 +31,10 @@ "string" ], "dependencies": { - "html-tags": "^3.0.0" + "html-tags": "^3.1.0" }, "devDependencies": { - "ava": "^1.4.1", - "xo": "^0.24.0" + "ava": "^3.15.0", + "xo": "^0.44.0" } } diff --git a/readme.md b/readme.md index 906f8c2..ed03c45 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@ $ npm install is-html ## Usage ```js -const isHtml = require('is-html'); +import isHtml from 'is-html'; isHtml('

I am HTML

'); //=> true diff --git a/test.js b/test.js index fdf6dd8..3cb17b2 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,5 @@ import test from 'ava'; -import isHtml from '.'; +import isHtml from './index.js'; test('detect HTML if it has doctype', t => { t.true(isHtml(''));