GitHub PullRequestReviewCommentEvent at 2014-03-06 22:36:39
Repository: js-select
Actor: harthur
Payload: {"comment":{"url":"https://api.github.com/repos/harthur/js-select/pulls/comments/10364861","id":10364861,"diff_hunk":"@@ -183,15 +183,44 @@ function matchesKey(part, context) {\n    }\n    if (part.expr) {\n       var expr = part.expr, lhs = expr[0], op = expr[1], rhs = expr[2];\n-      if (typeof node != \"string\"\n-          || (!lhs && op == \"=\" && node != rhs)   // :val(\"str\")\n-          || (!lhs && op == \"*=\" && node.indexOf(rhs) == -1)) { // :contains(\"substr\")\n-         return false;\n-      }\n+\t  return exprEval(expr,node);\n    }\n    return true;\n }\n \n+// copied from JSONSelect\n+// TODO remove if JSONSelect exports it\n+function is(o, t) { return typeof o === t; }\n+var operators = {\n+        '*':  [ 9, function(lhs, rhs) { return lhs * rhs; } ],\n+        '/':  [ 9, function(lhs, rhs) { return lhs / rhs; } ],\n+        '%':  [ 9, function(lhs, rhs) { return lhs % rhs; } ],\n+        '+':  [ 7, function(lhs, rhs) { return lhs + rhs; } ],\n+        '-':  [ 7, function(lhs, rhs) { return lhs - rhs; } ],\n+        '<=': [ 5, function(lhs, rhs) { return is(lhs, 'number') && is(rhs, 'number') && lhs <= rhs; } ],\n+        '>=': [ 5, function(lhs, rhs) { return is(lhs, 'number') && is(rhs, 'number') && lhs >= rhs; } ],\n+        '$=': [ 5, function(lhs, rhs) { return is(lhs, 'string') && is(rhs, 'string') && lhs.lastIndexOf(rhs) === lhs.length - rhs.length; } ],\n+        '^=': [ 5, function(lhs, rhs) { return is(lhs, 'string') && is(rhs, 'string') && lhs.indexOf(rhs) === 0; } ],\n+        '*=': [ 5, function(lhs, rhs) { return is(lhs, 'string') && is(rhs, 'string') && lhs.indexOf(rhs) !== -1; } ],\n+        '>':  [ 5, function(lhs, rhs) { return is(lhs, 'number') && is(rhs, 'number') && lhs > rhs; } ],\n+        '<':  [ 5, function(lhs, rhs) { return is(lhs, 'number') && is(rhs, 'number') && lhs < rhs; } ],\n+        '=':  [ 3, function(lhs, rhs) { return lhs === rhs; } ],\n+        '!=': [ 3, function(lhs, rhs) { return lhs !== rhs; } ],\n+        '&&': [ 2, function(lhs, rhs) { return lhs && rhs; } ],\n+        '||': [ 1, function(lhs, rhs) { return lhs || rhs; } ]\n+};\n+\n+function exprEval(expr, x) {\n+        if (expr === undefined) return x;","path":"index.js","position":37,"original_position":37,"commit_id":"651ad7bd04482f19db9347eb74d5de2a31eef701","original_commit_id":"651ad7bd04482f19db9347eb74d5de2a31eef701","user":{"login":"harthur","id":140420,"avatar_url":"https://gravatar.com/avatar/1c076cf3c465f363784904ed114a1e41?d=https%3A%2F%2Fidenticons.github.com%2F86a7bedbcdf934db12cabdde22b280f6.png&r=x","gravatar_id":"1c076cf3c465f363784904ed114a1e41","url":"https://api.github.com/users/harthur","html_url":"https://github.com/harthur","followers_url":"https://api.github.com/users/harthur/followers","following_url":"https://api.github.com/users/harthur/following{/other_user}","gists_url":"https://api.github.com/users/harthur/gists{/gist_id}","starred_url":"https://api.github.com/users/harthur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harthur/subscriptions","organizations_url":"https://api.github.com/users/harthur/orgs","repos_url":"https://api.github.com/users/harthur/repos","events_url":"https://api.github.com/users/harthur/events{/privacy}","received_events_url":"https://api.github.com/users/harthur/received_events","type":"User","site_admin":false},"body":"The rest of the file's style is like this:\r\n\r\n```\r\nif (expr === undefined) {\r\n    return x;\r\n}\r\n```\r\n\r\nSo stick to that (new lines and braces for one-line ifs)","created_at":"2014-03-06T22:36:39Z","updated_at":"2014-03-06T22:36:39Z","html_url":"https://github.com/harthur/js-select/pull/4#discussion_r10364861","pull_request_url":"https://api.github.com/repos/harthur/js-select/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/harthur/js-select/pulls/comments/10364861"},"html":{"href":"https://github.com/harthur/js-select/pull/4#discussion_r10364861"},"pull_request":{"href":"https://api.github.com/repos/harthur/js-select/pulls/4"}}}}