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

formatplus

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formatplus

Format strings inline!

  • 2.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

formatplus

Welcome!

FormatPlus is a brand new way of formatting your javascript strings. But different from default way of doing so, it is all done inline!

Install

npm i formatplus

Global Install

sudo npm i -g formatplus

2.0 Changelog

  • New readme

How-to-Use

Initalization

To actually give strings a FormatPlus method, you need to call formatplus() like so:

require("formatplus")();

Method 1

Method one involves numbers and can be used like this:

require("formatplus")();

console.log("{0} is so {1}!!! My favorite flavor is {2}.".FormatPlus("Ice Cream", "Good", "Banana-Mint"));

Method 2

A little more advaced, using objects.

console.log("{food} is so {level}!!! My favorite flavor is {flavor}.".FormatPlus({food: "Ice Cream", level: "Good", flavor: "Banana-Mint"}));

How it Works

Basically, the module is a function which adds a function to String.prototype called FormatPlus.

Source

If you would like to modify it, here is the base code:

module.exports=function(){
    String.prototype.FormatPlus = function(){
        let str = this.toString();
        
        if (arguments.length){
            const t = typeof arguments[0];
            const args = ("string" === t || "number" === t) ? arguments : arguments[0];
            
            for (let key in args) {
                str=str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]);
            }
        }
        
        return str;
    }
}
Raw Form
module.exports=function(){
    String.prototype.FormatPlus = function(){
        let str = this.toString();
        
        if (arguments.length){
            const t = typeof arguments[0];
            const args = ("string" === t || "number" === t) ? arguments : arguments[0];
            
            for (let key in args) {
                str=str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]);
            }
        }
        
        return str;
    }
}

Developer(s)

Tyler Kinney Studios

  • Tyler Kinney
  • Tyson Joe
  • Sean (REDACTED)

Publisher(s)

  • Tyler Kinney Publishing
Thanks for visiting

FAQs

Package last updated on 17 Jul 2022

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