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

format-string-by-pattern

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-string-by-pattern - npm Package Compare versions

Comparing version 0.3.1 to 1.0.0

2

dist/format-string-by-pattern.js

@@ -1,2 +0,2 @@

function e(e,r){if(!r)return r;var t,l,n,u,a,i,c,o,p=String(r).replace(/[^\da-zA-Z\n|]/g,""),v=e.split(/[^\da-zA-Z\n|]/g).filter(Boolean).map(function(e){return e.length}),s=e.split(/[\da-zA-Z\n|]/g).filter(Boolean);return e.startsWith(s[0])?s.reduce(function(e,r,u){return l=e.value.slice(0,t=v[u]),n=e.value.slice(t),{result:l?e.result.concat(r,l):e.result,value:n}},{result:"",value:p}).result.slice(0,e.length):v.reduce(function(e,r,t){return a="$1"+(u=s[t]||"")+"$2",i=r+e.prevSlice+e.prevSeparator.length,c=new RegExp("(.{"+i+"})(.)"),o=e.value.replace(c,a),{prevSeparator:u,prevSlice:i,value:o}},{prevSeparator:"",prevSlice:0,value:p}).value.slice(0,e.length)}module.exports=function(r,t){return t?e(r,t):function(t){return e(r,t)}};
function e(e,r){if(!r)return r;var t=String(r).replace(/[^\da-zA-Z\n|]/g,""),l=e.split(/[^\da-zA-Z\n|]/g).filter(Boolean).map(function(e){return e.length}),n=e.split(/[\da-zA-Z\n|]/g).filter(Boolean);return e.startsWith(n[0])?n.reduce(function(e,r,t){var n=l[t],u=e.value.slice(0,n),a=e.value.slice(n);return{result:u?e.result.concat(r,u):e.result,value:a}},{result:"",value:t}).result.slice(0,e.length):l.reduce(function(e,r,t){var l=n[t]||"",u="$1"+l+"$2",a=r+e.prevSlice+e.prevSeparator.length,i=new RegExp("(.{"+a+"})(.)");return{prevSeparator:l,prevSlice:a,value:e.value.replace(i,u)}},{prevSeparator:"",prevSlice:0,value:t}).value.slice(0,e.length)}module.exports=function(r,t){return t?e(r,t):function(t){return e(r,t)}};
//# sourceMappingURL=format-string-by-pattern.js.map

@@ -1,2 +0,2 @@

function e(e,r){if(!r)return r;var t,l,n,u,a,i,c,o,p=String(r).replace(/[^\da-zA-Z\n|]/g,""),v=e.split(/[^\da-zA-Z\n|]/g).filter(Boolean).map(function(e){return e.length}),s=e.split(/[\da-zA-Z\n|]/g).filter(Boolean);return e.startsWith(s[0])?s.reduce(function(e,r,u){return l=e.value.slice(0,t=v[u]),n=e.value.slice(t),{result:l?e.result.concat(r,l):e.result,value:n}},{result:"",value:p}).result.slice(0,e.length):v.reduce(function(e,r,t){return a="$1"+(u=s[t]||"")+"$2",i=r+e.prevSlice+e.prevSeparator.length,c=new RegExp("(.{"+i+"})(.)"),o=e.value.replace(c,a),{prevSeparator:u,prevSlice:i,value:o}},{prevSeparator:"",prevSlice:0,value:p}).value.slice(0,e.length)}module.exports=function(r,t){return t?e(r,t):function(t){return e(r,t)}};
function e(e,r){if(!r)return r;var t=String(r).replace(/[^\da-zA-Z\n|]/g,""),l=e.split(/[^\da-zA-Z\n|]/g).filter(Boolean).map(function(e){return e.length}),n=e.split(/[\da-zA-Z\n|]/g).filter(Boolean);return e.startsWith(n[0])?n.reduce(function(e,r,t){var n=l[t],u=e.value.slice(0,n),a=e.value.slice(n);return{result:u?e.result.concat(r,u):e.result,value:a}},{result:"",value:t}).result.slice(0,e.length):l.reduce(function(e,r,t){var l=n[t]||"",u="$1"+l+"$2",a=r+e.prevSlice+e.prevSeparator.length,i=new RegExp("(.{"+a+"})(.)");return{prevSeparator:l,prevSlice:a,value:e.value.replace(i,u)}},{prevSeparator:"",prevSlice:0,value:t}).value.slice(0,e.length)}module.exports=function(r,t){return t?e(r,t):function(t){return e(r,t)}};
//# sourceMappingURL=format-string-by-pattern.m.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){function e(e,t){if(!t)return t;var n,r,l,u,i,a,o,c,p=String(t).replace(/[^\da-zA-Z\n|]/g,""),f=e.split(/[^\da-zA-Z\n|]/g).filter(Boolean).map(function(e){return e.length}),s=e.split(/[\da-zA-Z\n|]/g).filter(Boolean);return e.startsWith(s[0])?s.reduce(function(e,t,u){return r=e.value.slice(0,n=f[u]),l=e.value.slice(n),{result:r?e.result.concat(t,r):e.result,value:l}},{result:"",value:p}).result.slice(0,e.length):f.reduce(function(e,t,n){return i="$1"+(u=s[n]||"")+"$2",a=t+e.prevSlice+e.prevSeparator.length,o=new RegExp("(.{"+a+"})(.)"),c=e.value.replace(o,i),{prevSeparator:u,prevSlice:a,value:c}},{prevSeparator:"",prevSlice:0,value:p}).value.slice(0,e.length)}module.exports=function(t,n){return n?e(t,n):function(n){return e(t,n)}}});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r():"function"==typeof define&&define.amd?define(r):r()}(0,function(){function e(e,r){if(!r)return r;var t=String(r).replace(/[^\da-zA-Z\n|]/g,""),n=e.split(/[^\da-zA-Z\n|]/g).filter(Boolean).map(function(e){return e.length}),l=e.split(/[\da-zA-Z\n|]/g).filter(Boolean);return e.startsWith(l[0])?l.reduce(function(e,r,t){var l=n[t],u=e.value.slice(0,l),a=e.value.slice(l);return{result:u?e.result.concat(r,u):e.result,value:a}},{result:"",value:t}).result.slice(0,e.length):n.reduce(function(e,r,t){var n=l[t]||"",u="$1"+n+"$2",a=r+e.prevSlice+e.prevSeparator.length,i=new RegExp("(.{"+a+"})(.)");return{prevSeparator:n,prevSlice:a,value:e.value.replace(i,u)}},{prevSeparator:"",prevSlice:0,value:t}).value.slice(0,e.length)}module.exports=function(r,t){return t?e(r,t):function(t){return e(r,t)}}});
//# sourceMappingURL=format-string-by-pattern.umd.js.map
{
"name": "format-string-by-pattern",
"version": "0.3.1",
"version": "1.0.0",
"description": "A module that formats a string based on a pattern",

@@ -5,0 +5,0 @@ "main": "dist/format-string-by-pattern.js",

@@ -14,3 +14,3 @@ <h1 align="center">

This module consists on a function that receives a pattern and a value and returns this value formatted according to the pattern. It doesn't work with every pattern, but it works with a lot of use cases.
This module consists on a function that receives a pattern and a value and returns this value formatted according to the pattern. It doesn't work with every pattern, but it works with a lot of use cases, especially if you build functions on top of this module.

@@ -44,2 +44,10 @@ ## Install

const formatOnlyNumbers = anyString => {
const onlyNumbers = anyString.replace(/[^\d]/g, '');
return formatStringByPattern('999-999-9999', onlyNumbers);
};
formatOnlyNumbers('1A2B3C4D5E6F7G8H9');
// '123-456-789'
// It works with curry too

@@ -46,0 +54,0 @@ const someFormat = formatStringByPattern('00.00');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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