Skip to content
Permalink
Browse files
Require Node.js 12.20 and move to ESM
  • Loading branch information
sindresorhus committed Sep 1, 2021
1 parent 86050bf commit 3cf9eacedbe29966ebf9ab54fb8e818714da0d76
Showing with 20 additions and 16 deletions.
  1. +2 −5 .github/workflows/main.yml
  2. +7 −3 index.js
  3. +1 −1 license
  4. +8 −5 package.json
  5. +1 −1 readme.md
  6. +1 −1 test.js
@@ -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
@@ -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);
}
@@ -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:

@@ -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"
}
}
@@ -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
@@ -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>'));

0 comments on commit 3cf9eac

Please sign in to comment.