stringsticker.js
What is stringsticker.js?
Stringsticker is a tool for rearranging strings into a different format while retaining parts of the string that may contain variables or other dynamic content.
Installation
stringsticker.js can be used via a script tag or importing as a module.
Script tag:
<script src="//cdn.jsdelivr.net/npm/@dunks1980/stringsticker.js/stringsticker.js"></script>
ES Module:
<script type="module" src="main.js"></script>
// In main.js
import ss from '//cdn.jsdelivr.net/npm/@dunks1980/stringsticker.js/stringsticker.mjs';
You may want to add a version number like this to prevent breaking changes: '//cdn.jsdelivr.net/npm/@dunks1980/stringsticker.js@< VERSION >/stringsticker.mjs' the version number is optional and can be acquired from going to the npm package page. Or if using node_modules: './node_modules/@dunks1980/stringsticker.js/stringsticker.mjs';
NPM Module:
npm i @dunks1980/stringsticker.js
import ss from '@dunks1980/stringsticker.js';
ss();
Usage
const output1 = ss(
"Then she visited her grandmother on Sunday.",
"{{1}} {{2}} {{3}} {{4}} {{5}} {{6}} {{7}}.",
"{{1}} {{6}} {{7}} {{2}} {{3}} {{4}} {{5}}."
);
console.log(output1); // Then on Sunday she visited her grandmother.
const output2 = ss(
"12/11/2024",
"{{day}}/{{month}}/{{year}}",
"{{year}}-{{month}}-{{day}}"
);
console.log(output2); // 2024-11-12