formatplus
v2.0.0
Published
Format strings inline!
Downloads
1
Readme
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
Regular Install (RECOMMENDED)
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