Socket
Socket
Sign inDemoInstall

bracketter

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bracketter

Parse and manipulate tokenized strings with ease!


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Install size
22.9 kB
Created
Weekly downloads
 

Readme

Source

Bracketter (bracketter)

Parse and manipulate tokenized strings with ease!

Description

So many file types... so many different tagging, wrapping, bracketting characters... <>, </>, [], {}, (), %%, __, etc., etc., etc.

The goal of this library is to provide a one-stop-shop utility for whatever format your tokenized strings are in.

CommonJS or Modules

Two versions of this project exist for your convenience. The main bracketter uses Module format while bracketter-js contains the same logic but written as CommonJS. If you're new to NodeJS, and not sure what you are using, take a look at the syntax you use for loading dependencies:

FormatSyntax
CommonJSconst { replace } = require('bracketter-js');
Modulesimport { replace } from 'bracketter';

Usage

During this experiemental stage, there is one single entrypoint, replace():

const result = replace({ 
  line,     // raw string of tokenized values
  values,   // object of key-value pairs
  defaults  // optional key-value pair object, like values,
});

Or, if you have a multiple lines to replace:

const result = replace({ 
  lines,    // array of strings
  values,   // object of key-value pairs
  defaults  // optional key-value pair object, like values,
});

Example Usage

If you're like me, seeing the code is everything. Here's a quick example to show how you might use the bracketter utility in your project:

import { replace } from '../../index.mjs';

const lines = [
  'Hello {name}! How are you?',
  'Today is %day%.',
];

const values = {
  name: 'World',
}

const defaults = {
  day: 'a great day',
}

const result = replace({ 
  lines,
  values,
  defaults,
});

console.log(result);

That code above will yield:

['Hello World! How are you?', 'Today is a great day.']

Token Nesting

One of the items I use this library for is the nesting of tokenized strings. Not too long ago I leveraged some 12-factor concepts to create a deployment engine for AWS and Azure using Terraform IaC packages. The IaC code had to be built on the fly and constructed by applying multiple layers of logic. Each layer could essentially change the previous for many reasons (security, quota limits, etc.). One of the techniques that allowed me to be successful was allowing each layer to apply concrete changes or new strings which could also be tokenized in preparation for the next stage. Anyway, long story short, bracketter employs this same nesting logic in case you would like to leverage a similar pattern.

Contact Info

This was a quick lil' project I whipped up for something I needed in an opensouce project. If you have interest in bracketter, please let me know so I will know to keep it alive. If there are any enhancements you can think of, I'd love to know that to! Until then...

Fred Lackey
http://fredlackey.com
fred.lackey@gmail.com

Keywords

FAQs

Last updated on 13 Jul 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc