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

manifold

v3.2.0

Published

Map regular expressions via strings to objects

Downloads

59

Readme

manifold NPM version

build

documentation - examples - install - todo - not a real horse

sample

var Manifold = require('manifold');
var app = new Manifold();

app.set('get /user/:page(\\d+)', {
  parent: 'get /user',
  handle: function getUserPage(){};
});

app.set('get /user', {
  picture: function getPicture(){
    // fetch that thing
  },
  render: function markup(){
    // you know, some markup
  }
});

app.get('get /user/10'); // =>
{
  notFound: false,
  path: 'get /user/10',
  url: '/user/10',
  match: 'get /user/10',
  params: { _: [ 'page' ], page: '10' },
  handle: [Function: getUserPage],
  picture: [Function: getPicture],
  render: [Function: markup]
}

documentation

The module.exports a constructor

var Manifold = require('manifold');

that takes no arguments

var manifold = new Manifold();

In all the following node refers to the object mapping path to object.

manifold.set([path, props])

set a path to regex mapping for an object

arguments

  • path type string

  • props type function or plainObject

  • when is a function it will be assigned to the props.handle

  • when is a plainObject, all option properties are passed first to a parser if there is one and if not, that property is cloned and assigned to the node props

returns this

The path is taken as a regular expression using the parth module, which uses the usual conventions on for path to regexp parsing. So you know... interesting things can happen.

samples

manifold.set('get /user/:page(\\d+)', function getUserPage(){
  // do stuff
});

manifold.get('get /user/10');
// =>
{
  notFound: false,
  path: 'get /user/10',
  url: '/user/10',
  match: 'get /user/10',
  params: { _: [ 'page' ], page: '10' },
  handle: [Function: getUserPage]
}

manifold.get([path, options, mod])

get an object matching the given path, clone it if necessary

arguments

  • path, optional, type string
  • options, optional, type object with all extra information
  • mod, type object. If is a:
    • plainObject with property ref, the node found will not be cloned
    • regular expression, are the props to skip while cloning

returns the object (cloned/by reference) node found

In addition, if the node has a parent it will inherit its properties while cloning.

sample

manifold.set('get /user/:page', {
  parent: 'get /user',
  handle: function getUserPage(){};
});

manifold.set('get /user', {
  picture: function getPicture(){
    // fetch that thing
  },
  render: function markup(){
    // you know, some markup
  }
});

manifold.get('get /user/10'); // =>
{
  notFound: false,
  path: 'get /user/10',
  url: '/user/10',
  match: 'get /user/10',
  params: { _: [ 'page' ], page: '10' },
  handle: [Function: getUserPage],
  picture: [Function: getPicture],
  render: [Function: markup]
}

instance properties

  • manifold.regex: regexes are stored here
  • manifold.store: key value store with all of the nodes stored

why

I Need it for the runtime module ;)

The project name is an homage to the concept of manifold. Beautiful creature of Math and Physics thought. BUT, this can't be considered the real thing. That is: this is not a manifold. I'd wish!

install

With npm

npm install manifold --save

examples

Run the example.js file.

test

$ npm test

➜  manifold (master) ✓ npm test
manifold
  sample
    ✓ data creation should not fail
    ✓ sample data should be random
  parse
    ✓ add test data
    ✓ should parse properties when one sets them
    ✓ should support objects for setting parsers
  rootNode
    ✓ add test data
    ✓ should have properties ({ref: true})
    ✓ should have properties ({ref: true})
    ✓ should not have properties ({ref: true})
    ✓ should have properties ({ref: true})
  parent
    ✓ add test data
    ✓ should have children added after parent is set
    ✓ should have the same parent by reference
    ✓ property should not be enumerable after overwrite
  children
    ✓ add test data
    ✓ should support single object as input
    ✓ should support array as input
    ✓ should have parent added after children were set
    ✓ should not be enumerable after overwrite
    ✓ should inherit from parent when


20 passing (35ms)

license