pax_global_header 0000666 0000000 0000000 00000000064 14313140347 0014512 g ustar 00root root 0000000 0000000 52 comment=5ff385f943afbe6d23a0e01e5e0444d88b4bee93
safe-regex-test-1.0.0/ 0000775 0000000 0000000 00000000000 14313140347 0014513 5 ustar 00root root 0000000 0000000 safe-regex-test-1.0.0/.eslintrc 0000664 0000000 0000000 00000000172 14313140347 0016337 0 ustar 00root root 0000000 0000000 {
"root": true,
"extends": "@ljharb",
"rules": {
"new-cap": [2, { "capIsNewExceptions": ["GetIntrinsic"] }],
},
}
safe-regex-test-1.0.0/.github/ 0000775 0000000 0000000 00000000000 14313140347 0016053 5 ustar 00root root 0000000 0000000 safe-regex-test-1.0.0/.github/FUNDING.yml 0000664 0000000 0000000 00000001112 14313140347 0017663 0 ustar 00root root 0000000 0000000 # These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/safe-regex-test
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
safe-regex-test-1.0.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14313140347 0020110 5 ustar 00root root 0000000 0000000 safe-regex-test-1.0.0/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000516 14313140347 0022670 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js < 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '< 10'
type: minors
command: npm run tests-only
node:
name: 'node < 10'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: 'echo tests completed'
safe-regex-test-1.0.0/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000206 14313140347 0023242 0 ustar 00root root 0000000 0000000 name: 'Tests: pretest/posttest'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/pretest.yml@main
safe-regex-test-1.0.0/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000521 14313140347 0022525 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js >= 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 10'
type: minors
command: npm run tests-only
node:
name: 'node >= 10'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: 'echo tests completed'
safe-regex-test-1.0.0/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000411 14313140347 0022070 0 ustar 00root root 0000000 0000000 name: Automatic Rebase
on: [pull_request_target]
jobs:
_:
name: "Automatic Rebase"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ljharb/rebase@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
safe-regex-test-1.0.0/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 14313140347 0024525 0 ustar 00root root 0000000 0000000 name: Require “Allow Edits”
on: [pull_request_target]
jobs:
_:
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- uses: ljharb/require-allow-edits@main
safe-regex-test-1.0.0/.gitignore 0000664 0000000 0000000 00000003251 14313140347 0016504 0 ustar 00root root 0000000 0000000 # Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
.npmignore
safe-regex-test-1.0.0/.npmrc 0000664 0000000 0000000 00000000067 14313140347 0015636 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
safe-regex-test-1.0.0/CHANGELOG.md 0000664 0000000 0000000 00000001443 14313140347 0016326 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v1.0.0 - 2022-09-22
### Commits
- Initial implementation, tests, readme [`0273e9f`](https://github.com/ljharb/safe-regex-test/commit/0273e9f96f4b09df413523f4faacc8ae9ac5e6cb)
- Initial commit [`b6c1edf`](https://github.com/ljharb/safe-regex-test/commit/b6c1edf740e6105fb71c34c1c69fadd837e8f7ab)
- npm init [`c7f5765`](https://github.com/ljharb/safe-regex-test/commit/c7f576580607b16458b5a16e6bfa3b639e49c6bd)
- Only apps should have lockfiles [`1162bf0`](https://github.com/ljharb/safe-regex-test/commit/1162bf011835040f7e2c9936734294b2d98536bf)
safe-regex-test-1.0.0/LICENSE 0000664 0000000 0000000 00000002057 14313140347 0015524 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2022 Jordan Harband
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:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
safe-regex-test-1.0.0/README.md 0000664 0000000 0000000 00000002717 14313140347 0016001 0 ustar 00root root 0000000 0000000 # safe-regex-test [![Version Badge][npm-version-svg]][package-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
Give a regex, get a robust predicate function that tests it against a string. This will work even if `RegExp.prototype` is altered later.
## Getting started
```sh
npm install --save safe-regex-test
```
## Usage/Examples
```js
var regexTester = require('safe-regex-test');
var assert = require('assert');
var tester = regexTester('a');
assert.ok(tester('a'));
assert.notOk(tester('b'));
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/safe-regex-test
[npm-version-svg]: https://versionbadg.es/ljharb/safe-regex-test.svg
[deps-svg]: https://david-dm.org/ljharb/safe-regex-test.svg
[deps-url]: https://david-dm.org/ljharb/safe-regex-test
[dev-deps-svg]: https://david-dm.org/ljharb/safe-regex-test/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/safe-regex-test#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/safe-regex-test.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/safe-regex-test.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/safe-regex-test.svg
[downloads-url]: https://npm-stat.com/charts.html?package=safe-regex-test
safe-regex-test-1.0.0/index.js 0000664 0000000 0000000 00000000662 14313140347 0016164 0 ustar 00root root 0000000 0000000 'use strict';
var callBound = require('call-bind/callBound');
var GetIntrinsic = require('get-intrinsic');
var isRegex = require('is-regex');
var $exec = callBound('RegExp.prototype.exec');
var $TypeError = GetIntrinsic('%TypeError%');
module.exports = function regexTester(regex) {
if (!isRegex(regex)) {
throw new $TypeError('`regex` must be a RegExp');
}
return function test(s) {
return $exec(regex, s) !== null;
};
};
safe-regex-test-1.0.0/package.json 0000664 0000000 0000000 00000003637 14313140347 0017012 0 ustar 00root root 0000000 0000000 {
"name": "safe-regex-test",
"version": "1.0.0",
"description": "Give a regex, get a robust predicate function that tests it against a string.",
"main": "index.js",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"",
"lint": "eslint --ext=js,mjs .",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"pretest": "npm run lint",
"tests-only": "tape test",
"test": "npm run tests-only",
"posttest": "aud --production"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ljharb/safe-regex-test.git"
},
"keywords": [
"regex",
"regexp",
"test",
"tester",
"safe",
"robust",
"exec"
],
"author": "Jordan Harband ",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/ljharb/safe-regex-test/issues"
},
"homepage": "https://github.com/ljharb/safe-regex-test#readme",
"dependencies": {
"call-bind": "^1.0.2",
"get-intrinsic": "^1.1.3",
"is-regex": "^1.1.4"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.0.0",
"aud": "^2.0.1",
"auto-changelog": "^2.4.0",
"es-value-fixtures": "^1.4.2",
"eslint": "=8.8.0",
"for-each": "^0.3.3",
"in-publish": "^2.0.1",
"npmignore": "^0.3.0",
"object-inspect": "^1.12.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.6.1"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
safe-regex-test-1.0.0/test/ 0000775 0000000 0000000 00000000000 14313140347 0015472 5 ustar 00root root 0000000 0000000 safe-regex-test-1.0.0/test/index.js 0000664 0000000 0000000 00000001556 14313140347 0017146 0 ustar 00root root 0000000 0000000 'use strict';
var test = require('tape');
var v = require('es-value-fixtures');
var forEach = require('for-each');
var inspect = require('object-inspect');
var regexTester = require('../');
test('regex tester', function (t) {
t.equal(typeof regexTester, 'function', 'is a function');
t.test('non-regexes', function (st) {
forEach(v.primitives.concat(v.objects), function (val) {
st['throws'](
function () { regexTester(val); },
TypeError,
inspect(val) + ' is not a regex'
);
});
st.end();
});
t.test('regexes', function (st) {
var tester = regexTester(/a/);
st.equal(typeof tester, 'function', 'returns a function');
st.equal(tester('a'), true, 'returns true for a match');
st.equal(tester('b'), false, 'returns false for a non-match');
st.equal(tester('a'), true, 'returns true for a match again');
st.end();
});
t.end();
});