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

fmtr

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fmtr - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

10

index.js

@@ -6,7 +6,9 @@ "use strict";

module.exports = function fmtr(str, obj) {
try {
return _.template(_.isString(str) ? str : '', { interpolate: /\$\{([^\}]+)\}/gm })(obj);
} catch (err) {
return (_.isString(str) ? str : '').replace(/\$\{([^\}]+)\}/gm, '');
if (typeof str !== "string") {
return '';
}
return str.replace(/\$\{([^\}]+)\}/gm, function (match, p1) {
return _.get(obj, p1) || '';
});
};

8

package.json
{
"name": "fmtr",
"version": "1.0.4",
"version": "1.0.5",
"description": "awesome string formatter",

@@ -27,8 +27,8 @@ "main": "index.js",

"dependencies": {
"lodash": "^4.11.1"
"lodash": "^4.17.1"
},
"devDependencies": {
"expect.js": "^0.3.1",
"mocha": "^2.4.5",
"jshint": "^2.9.1"
"mocha": "^3.1.2",
"jshint": "^2.9.4"
},

@@ -35,0 +35,0 @@ "jshintConfig": {

@@ -30,4 +30,19 @@ "use strict";

expect(fmtr('Xx ${foobar} xX', { baz: 123 })).to.be('Xx xX');
expect(fmtr('Xx ${foo} ${bar} xX', { bar: 123 })).to.be('Xx 123 xX');
});
it('should support deep paths', function () {
expect(fmtr('${foo.bar}', { foo: { bar: 1 } })).to.be('1');
expect(fmtr('${foo[1]}', { foo: [ 1, 2, 3 ] })).to.be('2');
});
it('should handle the example from the README.md', function () {
var user = {
username: 'alice',
spouse: 'bob',
enemy: 'eve'
};
expect(fmtr('${username} is married to ${spouse} and hates ${enemy}', user)).to.be("alice is married to bob and hates eve");
});
});
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