Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hokey-cokey

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hokey-cokey

Render values into templates OR extract values out of templates. That's what it's all about.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Hokey Cokey! Simple string template rendering and parameter value extracting

Travis CI semantic-release Conventional Commits Prettier npm

Hokey Cokey is a quick tool for extracting parameters from, and inserting parameters into, template strings:

  • Extract:
    • Match a string (e.g. places/france/paris/) against a template (e.g. places/:country/{city})
    • Return found values (e.g. { country: "france", city: "paris" })
  • Render:
    • With a template string (e.g. places/${country}/:city) and an object of values (e.g. { country: "france", city: "paris" })
    • Return the rendered output string after variables have been rendered in (e.g. places/france/paris/).

Things to know:

  • Works with parameters in :express, {jsx}, {{handlebars}} or ${es6} format.
  • Doesn't do anything complicated (like RegExp patterns, * glob patterns, or optional parameters).
  • Parameter names must match the simple format [a-zA-Z][a-zA-Z0-9].
  • When extracting values the template must have one character between each template parameter.
  • Template destructuring is cached internally for performance.
  • Well unit-tested and 100% covered.
  • Useful for cases where RegExps are too fussy and you want something chunky and robust.

Installation

npm install hokey-cokey

Usage

extract(): Get values out of a template

const { extract } = require('hokey-cokey');
const values = extract("places/{country}/{city}", "places/france/paris");

// { country: "france", city: "paris" }
console.log(values); 

render(): Inject values into a template

const { render } = require("hokey-cokey");
const output = render("blogs/:category/:slug", { category: "cheeses", slug: "stilton" });

// "places/france/paris"
console.log(output); 

Keywords

FAQs

Package last updated on 18 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc