pax_global_header00006660000000000000000000000064143131403470014512gustar00rootroot0000000000000052 comment=5ff385f943afbe6d23a0e01e5e0444d88b4bee93 safe-regex-test-1.0.0/000077500000000000000000000000001431314034700145135ustar00rootroot00000000000000safe-regex-test-1.0.0/.eslintrc000066400000000000000000000001721431314034700163370ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "new-cap": [2, { "capIsNewExceptions": ["GetIntrinsic"] }], }, } safe-regex-test-1.0.0/.github/000077500000000000000000000000001431314034700160535ustar00rootroot00000000000000safe-regex-test-1.0.0/.github/FUNDING.yml000066400000000000000000000011121431314034700176630ustar00rootroot00000000000000# 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/000077500000000000000000000000001431314034700201105ustar00rootroot00000000000000safe-regex-test-1.0.0/.github/workflows/node-aught.yml000066400000000000000000000005161431314034700226700ustar00rootroot00000000000000name: '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.yml000066400000000000000000000002061431314034700232420ustar00rootroot00000000000000name: '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.yml000066400000000000000000000005211431314034700225250ustar00rootroot00000000000000name: '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.yml000066400000000000000000000004111431314034700220700ustar00rootroot00000000000000name: 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.yml000066400000000000000000000003031431314034700245250ustar00rootroot00000000000000name: 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/.gitignore000066400000000000000000000032511431314034700165040ustar00rootroot00000000000000# 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/.npmrc000066400000000000000000000000671431314034700156360ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s safe-regex-test-1.0.0/CHANGELOG.md000066400000000000000000000014431431314034700163260ustar00rootroot00000000000000# 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/LICENSE000066400000000000000000000020571431314034700155240ustar00rootroot00000000000000MIT 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.md000066400000000000000000000027171431314034700160010ustar00rootroot00000000000000# 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.js000066400000000000000000000006621431314034700161640ustar00rootroot00000000000000'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.json000066400000000000000000000036371431314034700170120ustar00rootroot00000000000000{ "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/000077500000000000000000000000001431314034700154725ustar00rootroot00000000000000safe-regex-test-1.0.0/test/index.js000066400000000000000000000015561431314034700171460ustar00rootroot00000000000000'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(); });