Skip to content

Commit 69475a6

Browse files
committed
Add support for substr that matches PHP's slightly wider functionality
1 parent be552c1 commit 69475a6

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-logic-js",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"homepage": "https://github.com/jwadhams/json-logic-js",
55
"authors": [
66
"Jeremy Wadhams <jwadhams@dealerinspire.com>"

logic.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ http://ricostacruz.com/cheatsheets/umdjs.html
8181
"cat": function() {
8282
return Array.prototype.join.call(arguments, "");
8383
},
84+
"substr":function(source, start, end) {
85+
if(end < 0){
86+
// JavaScript doesn't support negative end, this emulates PHP behavior
87+
var temp = String(source).substr(start);
88+
return temp.substr(0, temp.length + end);
89+
}
90+
return String(source).substr(start, end);
91+
},
8492
"+": function() {
8593
return Array.prototype.reduce.call(arguments, function(a, b) {
8694
return parseFloat(a, 10) + parseFloat(b, 10);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-logic-js",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Build complex rules, serialize them as JSON, and execute them in JavaScript",
55
"main": "logic.js",
66
"directories": {

0 commit comments

Comments
 (0)