{"name":"randexp","version":"0.6.0","keywords":["regex","regexp","regular expression","random","test"],"author":{"url":"https://github.com/fent","name":"fent","email":"fentbox@gmail.com"},"license":"MIT","_id":"randexp@0.6.0","maintainers":[{"name":"fent","email":"fentbox@gmail.com"}],"homepage":"http://fent.github.io/randexp.js/","bugs":{"url":"https://github.com/fent/randexp.js/issues"},"dist":{"shasum":"e4e26bf36732138ce9c37cc08a980d26968b8f54","tarball":"http://registry-npm.ywwl.com/randexp/download/randexp-0.6.0.tgz","fileCount":5,"integrity":"sha512-RoIy+WJ6lTeUxp9C3F+CFdPahHRjI4JAQXheStD/3LBnqkDDQN22l/fnSMDkvjeyoeFhKFpg24ZYdi8BBYh6RA==","signatures":[{"sig":"MEYCIQDObLjLky7mS+rA5FsR4gTwdaNnNQ4XlQ/bVPPCjO053wIhAISZuF1R0iEybK9w2d+e34PAcsEflL1dvxhT/gxEEM7j","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQDyY1/KxeWJvXLWhU/Ko87QrYGG93/X0FRbOpU2zJ3+oAIgTWWYAkBLAAf6HxMtrqOvOUdITQk8/zervFW6Q/vbh8s=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/randexp@0.6.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":13503,"size":5639,"noattachment":false,"key":"/randexp/-/randexp-0.6.0.tgz"},"main":"./lib/randexp.js","types":"./types","engines":{"node":">=8"},"gitHead":"cb4231edddf1f56777bb874a8f59912c1cb3a220","scripts":{"test":"nyc --reporter=lcov --reporter=text-summary mocha -- test/*-test.js","dtslint":"dtslint types --onlyTestTsNext"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"4ac490b7-1566-4c38-a9ec-0b590ea9d404"}},"repository":{"url":"git://github.com/fent/randexp.js.git","type":"git"},"_npmVersion":"11.21.0","description":"Create random strings that match a given regular expression.","directories":{"lib":"./lib"},"_nodeVersion":"24.21.0","dependencies":{"ret":"^0.3.2","drange":"^2.0.1"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","mocha":"^7.0.1"},"_npmOperationalInternal":{"tmp":"tmp/randexp_0.6.0_1792052773696_0.9959630246668063","host":"s3://npm-registry-packages-npm-production"},"readme":"# randexp.js\n\nrandexp will generate a random string that matches a given RegExp Javascript object.\n\n[![npm](https://img.shields.io/npm/v/randexp)](https://www.npmjs.com/package/randexp)\n[![Node.js CI](https://github.com/fent/randexp.js/actions/workflows/nodejs.yml/badge.svg)](https://github.com/fent/randexp.js/actions/workflows/nodejs.yml)\n[![codecov](https://codecov.io/gh/fent/randexp.js/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/randexp.js)\n\n# Usage\n\n```js\nconst RandExp = require('randexp');\n\n// supports grouping and piping\nnew RandExp(/hello+ (world|to you)/).gen();\n// => hellooooooooooooooooooo world\n\n// sets and ranges and references\nnew RandExp(/<([a-z]\\w{0,20})>foo<\\1>/).gen();\n// => <m5xhdg>foo<m5xhdg>\n\n// wildcard\nnew RandExp(/random stuff: .+/).gen();\n// => random stuff: l3m;Hf9XYbI [YPaxV>U*4-_F!WXQh9>;rH3i l!8.zoh?[utt1OWFQrE ^~8zEQm]~tK\n\n// ignore case\nnew RandExp(/xxx xtreme dragon warrior xxx/i).gen();\n// => xxx xtReME dRAGON warRiOR xXX\n\n// dynamic regexp shortcut\nnew RandExp('(sun|mon|tue|wednes|thurs|fri|satur)day', 'i');\n// is the same as\nnew RandExp(new RegExp('(sun|mon|tue|wednes|thurs|fri|satur)day', 'i'));\n```\n\nIf you're only going to use `gen()` once with a regexp and want slightly shorter syntax for it\n\n```js\nconst randexp = require('randexp').randexp;\n\nrandexp(/[1-6]/); // 4\nrandexp('great|good( job)?|excellent'); // great\n```\n\nIf you miss the old syntax\n\n```js\nrequire('randexp').sugar();\n\n/yes|no|maybe|i don't know/.gen(); // maybe\n```\n\n# Motivation\n\nRegular expressions are used in every language, every programmer is familiar with them. Regex can be used to easily express complex strings. What better way to generate a random string than with a language you can use to express the string you want?\n\nThanks to [String-Random](http://search.cpan.org/~steve/String-Random-0.22/lib/String/Random.pm) for giving me the idea to make this in the first place and [randexp](https://github.com/benburkert/randexp) for the sweet `.gen()` syntax.\n\n# Default Range\n\nThe default generated character range includes printable ASCII characters.\n\n![ascii table](ascii.png)\n\nIn order to add or remove characters,\na `defaultRange` attribute is exposed. you can `subtract(from, to)` and `add(from, to)`\n```js\nconst randexp = new RandExp(/random stuff: .+/);\nrandexp.defaultRange.subtract(32, 126);\nrandexp.defaultRange.add(0, 65535);\nrandexp.gen();\n// => random stuff: 湐箻ໜ䫴␩⶛㳸長���邓蕲뤀쑡篷皇硬剈궦佔칗븛뀃匫鴔事좍ﯣ⭼ꝏ䭍詳蒂䥂뽭\n```\n\nYou can also change the default range by changing `RandExp.defaultRange`.\n\n# Custom PRNG\n\nThe default randomness is provided by `Math.random()`. If you need to use a seedable or cryptographic PRNG, you\ncan override `RandExp.randInt` or `randexp.randInt` (where `randexp` is an instance of `RandExp`). `randInt(from, to)` accepts an inclusive range and returns a randomly selected number within that range.\n\n# Infinite Repetitionals\n\nRepetitional tokens such as `*`, `+`, and `{3,}` have an infinite max range. In this case, randexp looks at its min and adds 100 to it to get a useable max value. If you want to use another int other than 100 you can change `RandExp.max` or the RandExp instance.\n\n```js\nconst randexp = new RandExp(/no{1,}/);\nrandexp.max = 1000000;\n```\n\nWith `RandExp.sugar()`\n\n```js\nconst regexp = /(hi)*/;\nregexp.max = 1000000;\n```\n\n# Bad Regular Expressions\n\nThere are some regular expressions which can never match any string.\n\n* Badly placed positionals such as `/a^/` and `/$c/m`. Randexp will ignore positional tokens.\n\n* Back references to non-existing groups like `/(a)\\1\\2/`. Randexp will ignore those references, returning an empty string for them. If the group exists only after the reference is used such as in `/\\1 (hey)/`, it will too be ignored.\n\n* Custom negated character sets with two sets inside that cancel each other out. Example: `/[^\\w\\W]/`. If you give this to randexp, it will return an empty string for this set since it can't match anything.\n\n\n# Projects based on randexp.js\n\n\n## JSON-Schema Faker\n\nUse generators to populate JSON Schema samples. See: [jsf on github](https://github.com/json-schema-faker/json-schema-faker/) and [jsf demo page](http://json-schema-faker.js.org/).\n\n\n# Install\n\n### Node.js\n\n    npm install randexp\n\n### Browser\n\nDownload the [minified version](https://github.com/fent/randexp.js/releases) from the latest release.\n\n\n# Tests\n\nTests are written with [mocha](https://mochajs.org)\n\n```bash\nnpm test\n```\n\n# Security\n\nTo report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.\n\n","publish_time":1792052773780,"_cnpm_publish_time":1792052773780,"dist-tags":{"latest":"0.6.1"}}