printin v1.0.6
PrintIn
This is a tool used to print data in a proper format according to your needs.
This use template strings to make printing flexible. Use {} in your string and pass the variable as parameters or pass them later by calling the returned function.
Comments
You can use comments in {} by writing the text between ~ for better readability.
print("{~message~} {~name~}", "Hello", "Node");
>> Hello Node
print("{~resource~} {}", "Memory", "Stack Overflow");
>> Memory Stack OverflowEscape Character
To esacpe the brackets and prevent yourself from errors, use {{ and }}
and the code will treat the brackets like normal characters.
print("{~message~} {~name~} {{🙃}}", "Hello", "Node");
>> Hello Node {🙃}Referencing
Empty
You can simpy use {} where you want to substitute data in the string. The data will be picked and placed from left to right. Brackets with comments ( eg. {~message~} ) will be also treated as empty brackets.
print("{} {} {} {}", "A")("B", "C", "D")
>> A B C DIndexes
Sometimes the order of passed elements does not match their order in the string. Use Indexes starting from 0 and the function will replace the passed Strings or Data from left to right as if they are in array.
print("{1} {3} {2} {0}", "A", "B", "C", "D")
>> B D C AKeys
You can also pass valid JS keys between the {} and then pass the JS Object to
with the same keys and their values. Values will be overridden from left to right.
print("{message} {name}", { message: "Hello", name: "Nathan" })
>> Hello NathanArrays
Pass the array rather together rather than passing the parameters individually. The values are extracted from the array and sorted out in 2 portions, ie. Strings and Numbers; and Objects. The Strings are then added from left to right. The Objects are evaluated in the same way.
print("{1} {3} {2} {0}", ["A", ["B", "C"]], ["D"])
>> B D C ATry combining it with chalk.js to see the different possiblities.
Current State
Current state of the string in returned function:
const message = print("{~message~} {~name~}", "Hello");
console.log(message.string);
>> Hello {~name~}Current state of unused brackets in returned function:
const message = print("{~message~} {~name~}", "Hello");
console.log(message.unused);
>> [ { unused: '{~name~}', index: 6 } ]Examples
CODE

OUTPUT

Note
The functions will be returned until all the brackets are occupied.In the case of strings like
print("{5}")You will need to pass 6 arguments where the first 5 arguments will be dumped and the 6th one is placed in the string.