Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including parenthesize with all npm packages installed. Try it out:

var parenthesize = require("parenthesize")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

parenthesize v1.0.0

wrap a string in parens, brackets, or whatever else you want


Wrap a string in parens, brackets, or whatever else you want.


var assert = require('assert')
var parenthesize = require('./')

parenthesize is a function that will wrap a given value in parenthesis:

assert.equal('(A comment)', parenthesize("A comment"))

You can replace the parens by providing an alternative delimiter:

assert.equal('[1]', parenthesize(1, '[]'))

If you want multi-character or other unusual delimiters, use an array for the second argument:

assert.equal('do\nputs "wat"\nend', parenthesize('puts "wat"', ['do\n', '\nend']))


module.exports = (String, (String|Array<String>)? ) => String



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free