{"id":16758440,"url":"https://github.com/kessler/pickpick-targeting-compiler","last_synced_at":"2025-07-10T00:39:21.565Z","repository":{"id":66642976,"uuid":"140843936","full_name":"kessler/pickpick-targeting-compiler","owner":"kessler","description":"compiles targeting expressions to javascript code for pickpick engine","archived":false,"fork":false,"pushed_at":"2024-04-23T09:20:57.000Z","size":23,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-01T19:06:19.902Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kessler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-07-13T12:23:22.000Z","updated_at":"2024-04-23T09:21:00.000Z","dependencies_parsed_at":"2024-04-23T13:22:49.429Z","dependency_job_id":"dd6607e0-41b3-41a6-8950-130f6d7922ea","html_url":"https://github.com/kessler/pickpick-targeting-compiler","commit_stats":null,"previous_names":["kessler/pickpick-targeting-compiler","ironsource/pickpick-targeting-compiler"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kessler/pickpick-targeting-compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fpickpick-targeting-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fpickpick-targeting-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fpickpick-targeting-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fpickpick-targeting-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kessler","download_url":"https://codeload.github.com/kessler/pickpick-targeting-compiler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fpickpick-targeting-compiler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264506308,"owners_count":23619010,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T04:05:19.362Z","updated_at":"2025-07-10T00:39:21.253Z","avatar_url":"https://github.com/kessler.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ANNOUCEMENT: repository changing ownership\nThis repository has changed ownership to the personal account of one of it's maintainers, [Yaniv Kessler](https://github.com/kessler)\n\nOwnership change will also occur on the npm registry to [Yaniv Kessler](https://www.npmjs.com/~kessler)\n\n# pickpick-targeting-compiler\n\n**compiles targeting expressions to javascript code for pickpick engine**\n\n-   uses [jsep](https://github.com/soney/jsep) to parse expressions and turn them into a javascript function that evaluates a conditiongiven a certain input.\n-   uses the `vm` module to have isolated context\n-   in addition to normal javascript operators, there are some special operators (see below for example):\n    -   `in` is exactly `Array.includes`\n    -   `match` regexp test\n    -   `startsWith` and `endsWith` is exactly `String.startsWith` and `String.endsWith` respectively\n-   exposes a bunch of useful `is*` functions from `util` module\n-   open for extension via user defined envinronment accessible using `$`\n\n## example\n\n`npm i pickpick-targeting-compiler`\n\n```js\nconst assert = require('assert')\nconst compile = require('pickpick-targeting-compiler')\n\n// intentionally using var here \n\n// all normal js operators apply\nvar { isMatch, features } = compile('_.geo === \"US\"')\nassert(isMatch({ geo: 'US' }))\n\nvar { isMatch, features } = compile('_.number \u003e= 0')\nassert(isMatch({ number: 1 }))\nassert(isMatch({ number: 2 }))\nassert(isMatch({ number: 3 }))\n\n// can create compound logical statements\nvar { isMatch, features } = compile('_.geo === \"US\" \u0026\u0026 _.number \u003e 5')\nassert(isMatch({ geo: 'US', number: 8 }))\n\n// in operator - same as Array.includes(value)\nvar { isMatch, features } = compile('_.geo in [\"US\", \"MX\"]')\nassert(isMatch({ geo: 'US' }))\n\n// operators apply to context data as well\nvar { isMatch, features } = compile('_.geo in _.page')\nassert(isMatch({ geo: 'US', page: [\"US\", \"MX\"] }))\n\n// startsWith operator - same as String.startsWith(string)\nvar { isMatch, features } = compile('_.geo startsWith \"x\"')\nassert(isMatch({ geo: 'xyz' }))\n\n// endsWith operator - same as String.endsWith(string)\nvar { isMatch, features } = compile('_.geo endsWith \"z\"')\nassert(isMatch({ geo: 'xyz' }))\n\n// match operator for literal regular expressions, same as /regex/g.test('value')\nvar { isMatch, features } = compile('_.geo match \"[0-9]\"')\nassert(isMatch({ geo: 0 }))\n\n// deeplyEquals operator performs a deep equal comparison (uses [lodash.isEqual](https://lodash.com/docs/4.17.10#isEqual))\nvar { isMatch, features } = compile('_.geo deeplyEquals [1, 2, 3]')\nassert(isMatch({ geo: [1, 2, 3] }))\n\n// exposes a bunch of isSomething from util:\n// isNullOrUndefined,\n// isNull,\n// isUndefined,\n// isString,\n// isNumber,\n// isArray,\n// isObject,\n// isBoolean,\n// isDate,\n// isNull,\n// isPrimitive\nvar { isMatch, features } = compile('isNumber(_.geo)')\nassert(isMatch({ geo: 0 }))\n\n// provide user defined functions and data\nconst userEnvironment = { x: [1, 2, 3], isOk: (arg) =\u003e arg.startsWith('x') }\nvar { isMatch, features } = compile('_.geo in $.x \u0026\u0026 $.isOk(_.page)', { userEnvironment })\nassert(isMatch({ geo: 1, page: 'x.html' }))\n```\n\n## api\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n#### Table of Contents\n\n-   [compile](#compile)\n\n### compile\n\n[index.js:56-156](https://github.com/ironSource/pickpick-targeting-compiler/blob/5059d0b7773162460d5ae0d9b10f72d883e6aad9/index.js#L56-L156 \"Source code on GitHub\")\n\nCompile an expression into a resuable javascript function\n\n**Parameters**\n\n-   `expression` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** any expression that can be parsed by [jsep](https://github.com/soney/jsep)\n-   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**  (optional, default `{}`)\n    -   `options.matcherProperty` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** return the match function using a different property name in the compound return value, e.g: (optional, default `'isMatch'`)\n    -   `options.userEnvironment` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** allows the user to inject additional functionality that will be exposed to the expression. e.g: (optional, default `{}`)\n    -   `options.userEnvNamespace` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** change the name used to access user environment in an expression (optional, default `$`)\n    -   `options.inputNamespace` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** change the name used to access input in the expression (optional, default `_`)\n\n**Examples**\n\n```javascript\n// options.matcherProperty\n \n   // normally this would be isMatch instead of 'foo'\n   let { foo } = compile('_.geo === \"1\"', { matcherProperty: 'foo' })\n```\n\n```javascript\n// options.userEnvironment\n   \n   let userEnvironment = {\n \t    geos: ['MX', 'US', 'IL'],\n  \t    format: value =\u003e value.toUpperCase()\n   }\n   \n   let { isMatch } = compile('$.format(_.geo) in $.geos', { userEnvironment })\n```\n\nReturns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that accepts input and returns a boolean value\n\n## license\n\n[MIT](http://opensource.org/licenses/MIT) © ironSource LTD\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fpickpick-targeting-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkessler%2Fpickpick-targeting-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fpickpick-targeting-compiler/lists"}