Skip to content

Commit

Permalink
added a new option called keepTypeof
Browse files Browse the repository at this point in the history
  • Loading branch information
thadeu committed Jan 16, 2024
1 parent 899b022 commit eabcfde
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 10 deletions.
4 changes: 3 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
type Options = {
strict?: boolean;
keepTypeof?: boolean;
};
declare class DryReplacer {
data: object;
strict: boolean;
strict?: boolean;
keepTypeof?: boolean;
constructor(data: object, options?: Options);
replaceValue(key: string, value: any, data: object, template: object): void;
recursiveReplace(data: object, template: any): object;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import r from"lodash.get";import t from"lodash.set";import e from"lodash.isarray";import n from"lodash.isplainobject";function a(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}var i=/*#__PURE__*/function(){function i(r,t){this.data=void 0,this.strict=!0,this.data=r,this.strict=null==t?void 0:t.strict}var o=i.prototype;return o.replaceValue=function(e,n,i,o){var c=String(n).match(/{{.*?}}/g);if(c)for(var l,s=function(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(e)return(e=e.call(r)).next.bind(e);if(Array.isArray(r)||(e=function(r,t){if(r){if("string"==typeof r)return a(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?a(r,t):void 0}}(r))){e&&(r=e);var n=0;return function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(c.reverse());!(l=s()).done;){var u=l.value,f=u.replace(/[{}]/g,""),p=r(o,e),d=r(i,f),v=d;["undefined",void 0,null,"string"].includes(typeof d)&&(v=p.replace(u,this.strict?d:d||"")),["number"].includes(typeof d)&&(v=p.replace(u,d)),t(o,e,v)}},o.recursiveReplace=function(r,t){for(var a=this,i=0,o=Object.keys(t);i<o.length;i++){var c=o[i],l=t[c];n(l)?this.recursiveReplace(r,l):e(l)?l.map(function(t){return a.recursiveReplace(r,t)}):this.replaceValue(c,l,r,t)}return t},o.try=function(r){var t=JSON.parse(r);return this.recursiveReplace(this.data,t),t},i}();export{i as default};
import e from"lodash.get";import r from"lodash.set";import t from"lodash.isarray";import n from"lodash.isplainobject";function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}var o=/*#__PURE__*/function(){function o(e,r){this.data=void 0,this.strict=!0,this.keepTypeof=!1,this.data=e,this.strict=null==r?void 0:r.strict,this.keepTypeof=null==r?void 0:r.keepTypeof}var a=o.prototype;return a.replaceValue=function(t,n,o,a){var s=String(n).match(/{{.*?}}/g);if(s)for(var l,c=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(s.reverse());!(l=c()).done;){var u=l.value,p=u.replace(/[{}]/g,""),f=e(a,t),d=e(o,p),v=d;["undefined",void 0,null,"string"].includes(typeof d)&&(v=f.replace(u,this.strict?d:d||"")),["number"].includes(typeof d)&&(v=f.replace(u,d),this.keepTypeof&&/^-?\.?_?\d+$/.test(v)&&(v=Number(v))),r(a,t,v)}},a.recursiveReplace=function(e,r){for(var i=this,o=0,a=Object.keys(r);o<a.length;o++){var s=a[o],l=r[s];n(l)?this.recursiveReplace(e,l):t(l)?l.map(function(r){return i.recursiveReplace(e,r)}):this.replaceValue(s,l,e,r)}return r},a.try=function(e){var r=JSON.parse(e);return this.recursiveReplace(this.data,r),r},o}();export{o as default};
//# sourceMappingURL=index.mjs.map
Loading

0 comments on commit eabcfde

Please sign in to comment.