How to use the regexparam.toString function in regexparam

To help you get started, we’ve selected a few regexparam examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lukeed / navaid / builder.js View on Github external
const fs = require('fs');
const mkdir = require('mk-dirs');
const pretty = require('pretty-bytes');
const { minify } = require('terser');
const sizer = require('gzip-size');
const pkg = require('./package');
const ESM = fs.readFileSync('src/index.js', 'utf8');
const regexparam = require('regexparam').toString();

mkdir('dist').then(() => {
	// Copy as is for ESM
	fs.writeFileSync(pkg.module, ESM);

	// Mutate (im|ex)ports for CJS
	const CJS = regexparam.replace('function ', 'function convert ').concat(
		ESM.replace(`import convert from 'regexparam';`, '')
			.replace(/export default/, 'module.exports =')
	);

	fs.writeFileSync(pkg.main, CJS);

	// Minify & print gzip-size
	const { code } = minify(CJS, { toplevel:true, compress:{ passes:10 } });
	console.log(`> gzip size: ${pretty(sizer.sync(code))}`);
github lukeed / route-manifest / bin / index.js View on Github external
const fs = require('fs');
const mkdir = require('mk-dirs');
const pretty = require('pretty-bytes');
const { minify } = require('terser');
const sizer = require('gzip-size');
const pkg = require('../package');

const ESM = fs.readFileSync('src/index.js', 'utf8');
const regexparam = require('regexparam').toString();

mkdir('dist').then(() => {
	// Copy as is for ESM
	fs.writeFileSync(pkg.module, ESM);

	// Mutate (im|ex)ports for CJS
	const CJS = ESM.replace(
		`import toRegExp from 'regexparam';`,
		`var toRegExp = require('regexparam');`
	).replace(/export default/, 'module.exports =')

	fs.writeFileSync(pkg.main, CJS);

	// Mutate again for UMD prep :: inline dependency
	const INLINED = regexparam.replace('function ', 'function toRegExp').concat(
		CJS.replace(`var toRegExp = require('regexparam');`, '')

regexparam

A tiny (399B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇‍

MIT
Latest version published 12 months ago

Package Health Score

68 / 100
Full package analysis

Popular regexparam functions