Skip to content

Commit

Permalink
Require Node.js 12.20 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 1, 2021
1 parent 86050bf commit 3cf9eac
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions index.js
@@ -1,7 +1,11 @@
'use strict';
const htmlTags = require('html-tags');
import htmlTags from 'html-tags';

const basic = /\s?<!doctype html>|(<html\b[^>]*>|<body\b[^>]*>|<x-[^>]+>)+/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);
}
2 changes: 1 addition & 1 deletion 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:

Expand Down
13 changes: 8 additions & 5 deletions package.json
Expand Up @@ -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"
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -13,7 +13,7 @@ $ npm install is-html
## Usage

```js
const isHtml = require('is-html');
import isHtml from 'is-html';

isHtml('<p>I am HTML</p>');
//=> true
Expand Down
2 changes: 1 addition & 1 deletion 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('<!doctype html>'));
Expand Down

0 comments on commit 3cf9eac

Please sign in to comment.