npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

delims

v0.4.2

Published

Generate RegExp for delimiters, to be used with templates, files or data streams.

Downloads

14,004

Readme

delims NPM version

Generate RegExp for delimiters, to be used with templates, files or data streams.

BREAKING API CHANGES!

Heads up! please read the API documentation to see the changes made in v0.3.0.

Install with npm

npm i delims --save

Install with bower

bower install delims --save

Run tests

npm test

Usage

var Delims = require('delims');
var delims = new Delims();

API

.templates

Create delimiter regex for templates.

Example:

Let's say you want to use curly braces as delimiters for Lo-Dash templates instead of angle brackes, e.g. {%= name %}.

var settings = delims.templates(['{{', '}}']);

// use it like this
var tmpl = _.template('{%= name %}', {name: 'Jon'}, settings);
console.log(tmpl);
//=> Jon

The full object returned looks something like:

{
  beginning: '',
  matter: '([\\s\\S]+?)',
  body: '',
  end: '',
  flags: 'g',
  noncapture: false,
  delims: [ '{%', '%}' ],
  open: '{%',
  close: '%}',
  evaluate: /{%([\s\S]+?)%}/g,
  interpolate: /{%=([\s\S]+?)%}/g,
  escape: /{%-([\s\S]+?)%}/g
}

.matter

Create delimiter regex for front-matter.

delims.matter(['~~~', '~~~']);
//=> '/^~~~([\\s\\S]+?)~~~([\\s\\S]+|\\s?)$/';

delims.matter(['~{3}', '~{3}']);
//=> '/^~{3}([\\s\\S]+?)~{3}([\\s\\S]+|\\s?)$/';

Read more about delimiters.

about delimiters

Type: Array

Default: ['---', '---']

An array of strings is appropriate for typical use cases, with the first item in the array being the "opening" delimiter, and the second item being the "closing" delimiter. In cases when multiple delimiters are required, e.g. --- or ~~~, an array of arrays may be passed in, where the first array will be used as opening delimiters and the second array will be used as closing delimiters.

Additionally, when multiple arrays are passed in the generated delimiters will be wrapped in non-capturing RegExp groups. For example, this:

delims([
  ['---', '~~~'], // delimiter 1
  ['---', '~~~']  // delimiter 2
]);

will result in something like this:

// for clarity, only the regex for delimiters is shown here
(?:---|~~~)/*other regex*/(?:---|~~~)

(Warning! Passing in multiple delimiters is a good way to cause delimiter collision, you best avoid doing so accept for running tests. Don't say I didn't warn you!)

options

An object of options may be passed as a second parameter. Example:

delims(['---', '---'], options);

Here are the available options and their defaults, starting with boundary options:

Boundary options

In addition to the delimiters themselves, these additional boundary options are available for increased flexibility.

matter

Type: Boolean

Default: ([\s\S]+?)

This is the "content" between the delimiters. YAML Front Matter being the inspiration for matter. See the examples.

body

Type: Boolean

Default: ([\s\S]+|\s?)

The "content" after the delims

RegExp Options

beginning

Type: Boolean

Default: ^

^ Matches beginning of input. See the Mozilla RegEx documentation.

end

Type: Boolean

Default: $

$ Matches end of input. See the Mozilla RegEx documentation.

escape

Type: Boolean

Default: false

Escape custom regex used for delimiters. E.g. ['{%', '%}'] will be escaped to ['\\{\\%', '\\%\\}'] before being passed to new RegExp().

noncapture

Type: Boolean

Default: false

Build a non-capture group. Disabled by default, but enabled by default when multiple delimiters are passed in.

flags

Type: Boolean

Default: undefined

  • g: global match
  • i: ignore case
  • m: multiline, so that beginning and end characters, ^ and $, work over multiple lines. See the Mozilla RegEx documentation.

Examples

A delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data streams. --Wikipedia

YAML Front Matter

image


Lo-Dash Templates

image


Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors. Released under the MIT license


This file was generated by verb-cli on September 26, 2014.