{"name":"jsep","version":"1.0.1-alpha","author":{"url":"http://from.so/","name":"Stephen Oney","email":"swloney@gmail.com"},"license":"MIT","_id":"jsep@1.0.1-alpha","homepage":"https://ericsmekens.github.io/jsep/","bugs":{"url":"https://github.com/EricSmekens/jsep/issues"},"dist":{"shasum":"e90f1058639bf202e2d2890c518651e6cb0d68f5","tarball":"http://registry-npm.ywwl.com/jsep/download/jsep-1.0.1-alpha.tgz","fileCount":16,"integrity":"sha512-XQHxNhseQu16RvSjdzOn0hYF2Qw4Oi2TltmbC7iazKqtiUnROXD4ErynhHy+CW2PR6PYgRLDyyuQgGkN0cH+DA==","signatures":[{"sig":"MEYCIQC1BC0AAGCgcLj2Ho8XKDp/33QMWHpiR+W7geYWZ19W+wIhAKgZlgpMb5/k5hkwgiw5Vb7jdt1n9KJBEHddd7BRDNeE","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":380952,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJV/zCRA9TVsSAnZWagAAh/EP/1GP1I+63ge0vNbGmPsy\nbwP8KMifcl5G4xEh2YUmhc7jPrpqq2h16bj0+bmdSXFRm6QstvSwTFh6g2fc\nUrevHhQGzOI4s23lBRdwMXu3C8qLIPcGBWwm/YiK6Q/rZ31RkwTWBvzoB/hp\nE3NUmL5BzhwYpUdzT0oxEjPA3OcLDU21C7tFcy7JV12UZ469NnEpDoT6aGiL\np2JXDLF7HViBxWjT2Y4zly00nwKD9dFEk3bWDNRx+llVydrI36EZgWRhXJXV\nekr0Cwd436PThv1ViPDnVkni5qEKbPckxqcqB1EB2lsa6eb2HxaGbTVE9nK4\nYpli0JiviyrzxEEDocejyOJ6/b+KBUU4AyK5t3ykpgZ9Itfb8AQAB64pKVjR\n/XEaVET7O0/TNp1zodxRyaUnS6gvrrYXlpZRZrnF0ouSHFHckSLl36jXFM/r\nVlZCGvIzvAsu7I6y6yl1JrjgreYfQ+sEZ8gD4YX0l9ROe2GziB0TDQJyF8TF\nmad0Xyl7qfj2fty3DL0rH7HSUyBWRESiNYYPBulvE3sMPEuGSxgl+Kf+Ey01\n5ntfoIKANO/k0tkw+evzl69t4RlBdu81jc9QDYSF1tWiQKmRXHLYBAf+weds\n/4rwexvt0WMk7r2W4wmhJ2avMeeJLnrqyd+IhKDqrAi1gAA2yHAqgv7obRb0\n3RhH\r\n=rAiN\r\n-----END PGP SIGNATURE-----\r\n","size":95171,"noattachment":false,"key":"/jsep/-/jsep-1.0.1-alpha.tgz"},"main":"./dist/cjs/jsep.cjs.js","type":"module","module":"./dist/jsep.js","engines":{"node":">= 10.16.0"},"exports":{".":{"default":"./dist/jsep.js","require":"./dist/cjs/jsep.cjs.js"}},"gitHead":"94eda91e9b8b9631bffd9defadceae8861d94508","private":false,"scripts":{"lint":"npx eslint src/**/*.js test/*.js test/packages/**/*.js packages/**/*.js","test":"npx http-server -p 49649 --silent & npx node-qunit-puppeteer http://localhost:49649/test/unit_tests.html","build":"npx rollup -c && cp package-cjs.json dist/cjs/package.json","docco":"npx docco src/jsep.js --css=src/docco.css --output=annotated_source/","default":"npm run lint && npm run build && npm run test && npm run docco","test:all":"pnpm run test -r","build:all":"pnpm run build -r","build:watch":"npx rollup -c --watch"},"typings":"typings/tsd.d.ts","_npmUser":{"name":"smekkie","email":"ericsmekens@msn.com"},"repository":{"url":"git+https://github.com/EricSmekens/jsep.git","type":"git"},"workspaces":["./packages/*"],"_npmVersion":"6.14.14","description":"a tiny JavaScript expression parser","directories":{"test":"test"},"_nodeVersion":"16.6.2","_hasShrinkwrap":false,"devDependencies":{"docco":"^0.8.1","eslint":"^7.23.0","rollup":"^2.44.0","puppeteer":"^5.5.0","http-server":"^0.12.3","node-qunit-puppeteer":"^2.1.0","rollup-plugin-delete":"^2.0.0","rollup-plugin-terser":"^7.0.2","@rollup/plugin-replace":"^2.4.2"},"_npmOperationalInternal":{"tmp":"tmp/jsep_1.0.1-alpha_1629839347175_0.8641868231150263","host":"s3://npm-registry-packages"},"readme":"## jsep: A Tiny JavaScript Expression Parser\n\n[jsep](https://ericsmekens.github.io/jsep/) is a simple expression parser written in JavaScript. It can parse JavaScript expressions but not operations. The difference between expressions and operations is akin to the difference between a cell in an Excel spreadsheet vs. a proper JavaScript program.\n\n### Why jsep?\n\nI wanted a lightweight, tiny parser to be included in one of my other libraries. [esprima](http://esprima.org/) and other parsers are great, but had more power than I need and were *way* too large to be included in a library that I wanted to keep relatively small.\n\njsep's output is almost identical to [esprima's](http://esprima.org/doc/index.html#ast), which is in turn based on [SpiderMonkey's](https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API).\n\n### Custom Build\n\nWhile in the jsep project directory, run:\n\n```bash\nnpm install\nnpm run default\n```\n\nThe jsep built files will be in the build/ directory.\n\n### Usage\n\n#### Client-side\n\n```html\n<script type=\"module\">\n  import jsep from '/PATH/TO/jsep.min.js';\n  const parsed = jsep('1 + 1');\n</script>\n\n<script src=\"/PATH/TO/jsep.iife.min.js\"></script>\n  ...\nlet parse_tree = jsep(\"1 + 1\");\n```\n\n#### Node.JS\n\nFirst, run `npm install jsep`. Then, in your source file:\n\n```javascript\n// ESM:\nimport jsep from 'jsep';\nconst parse_tree = jsep('1 + 1');\n\n// or:\nimport { Jsep } from 'jsep';\nconst parse_tree = Jsep.parse('1 + 1');\n\n\n// CJS:\nconst jsep = require('jsep').default;\nconst parsed = jsep('1 + 1');\n\n// or:\nconst { Jsep } = require('jsep');\nconst parse_tree = Jsep.parse('1 + 1');\n```\n\n#### Custom Operators\n\n```javascript\n// Add a custom ^ binary operator with precedence 10\n// (Note that higher number = higher precedence)\njsep.addBinaryOp(\"^\", 10);\n\n// Add exponentiation operator (right-to-left)\njsep.addBinaryOp('**', 11, true);\n\n// Add a custom @ unary operator\njsep.addUnaryOp('@');\n\n// Remove a binary operator\njsep.removeBinaryOp(\">>>\");\n\n// Remove a unary operator\njsep.removeUnaryOp(\"~\");\n```\n\n#### Custom Identifiers\n\nYou can add or remove additional valid identifier chars. ('_' and '$' are already treated like this.)\n\n```javascript\n// Add a custom @ identifier\njsep.addIdentifierChar(\"@\");\n\n// Removes a custom @ identifier\njsep.removeIdentifierChar('@');\n```\n\n### Plugins\nJSEP supports defining custom hooks for extending or modifying the expression parsing.\nPlugins are registered by calling `jsep.plugins.register()` with the plugin(s) as the argument(s).\n\n#### JSEP-provided plugins:\n|                                   |                                                                                           |\n|-----------------------------------|-------------------------------------------------------------------------------------------|\n| [ternary](packages/ternary)       | Built-in by default, adds support for ternary `a ? b : c` expressions                     |\n| [arrow](packages/arrow)           | Adds arrow-function support: `v => !!v`                                                   |\n| [assignment](packages/assignment) | Adds assignment and update expression support: `a = 2`, `a++`                             |\n| [comment](packages/comment)       | Adds support for ignoring comments: `a /* ignore this */ > 1 // ignore this too`          |\n| [new](packages/new)               | Adds 'new' keyword support: `new Date()`                                                  |\n| [numbers](packages/numbers)       | Adds hex, octal, and binary number support, ignore _ char                                 |\n| [object](packages/object)         | Adds object expression support: `{ a: 1, b: { c }}`                                       |\n| [regex](packages/regex)           | Adds support for regular expression literals: `/[a-z]{2}/ig`                              |\n| [spread](packages/spread)         | Adds support for the spread operator, `fn(...[1, ...a])`. Works with `object` plugin, too |\n| [template](packages/template)     | Adds template literal support: `` `hi ${name}` ``                                         |\n|                                   |                                                                                           |\n\n#### How to add plugins:\nPlugins have a `name` property so that they can only be registered once.\nAny subsequent registrations will have no effect. Add a plugin by registering it with JSEP:\n\n```javascript\nimport jsep from 'jsep';\nimport ternary from '@jsep-plugin/ternary';\nimport object from '@jsep-plugin/object';\njsep.plugins.register(object);\njsep.plugins.register(ternary, object);\n```\n\n#### List plugins:\nPlugins are stored in an object, keyed by their name.\nThey can be retrieved through `jsep.plugins.registered`.\n\n#### Writing Your Own Plugin:\nPlugins are objects with two properties: `name` and `init`.\nHere's a simple plugin example:\n```javascript\nconst plugin = {\n  name: 'the plugin',\n  init(jsep) {\n    jsep.addIdentifierChar('@');\n    jsep.hooks.add('gobble-expression', function myPlugin(env) {\n      if (this.char === '@') {\n        this.index += 1;\n        env.node = {\n          type: 'MyCustom@Detector',\n        };\n      }\n    });\n  },\n};\n```\nThis example would treat the `@` character as a custom expression, returning\na node of type `MyCustom@Detector`.\n\n##### Hooks\nMost plugins will make use of hooks to modify the parsing behavior of jsep.\nAll hooks are bound to the jsep instance, are called with a single argument, and return void.\nThe `this` context provides access to the internal parsing methods of jsep\nto allow reuse as needed. Some hook types will pass an object that allows reading/writing\nthe `node` property as needed.\n\n##### Hook Types\n* `before-all`: called just before starting all expression parsing.\n* `after-all`: called after parsing all. Read/Write `arg.node` as required.\n* `gobble-expression`: called just before attempting to parse an expression. Set `arg.node` as required.\n* `after-expression`: called just after parsing an expression. Read/Write `arg.node` as required.\n* `gobble-token`: called just before attempting to parse a token. Set `arg.node` as required.\n* `after-token`: called just after parsing a token. Read/Write `arg.node` as required.\n* `gobble-spaces`: called when gobbling whitespace.\n\n##### The `this` context of Hooks\n```typescript\nexport interface HookScope {\n    index: number;\n    readonly expr: string;\n    readonly char: string; // current character of the expression\n    readonly code: number; // current character code of the expression\n    gobbleSpaces: () => void;\n    gobbleExpressions: (untilICode?: number) => Expression[];\n    gobbleExpression: () => Expression;\n    gobbleBinaryOp: () => PossibleExpression;\n    gobbleBinaryExpression: () => PossibleExpression;\n    gobbleToken: () => PossibleExpression;\n    gobbleTokenProperty: (node: Expression) => Expression;\n    gobbleNumericLiteral: () => PossibleExpression;\n    gobbleStringLiteral: () => PossibleExpression;\n    gobbleIdentifier: () => PossibleExpression;\n    gobbleArguments: (untilICode: number) => PossibleExpression;\n    gobbleGroup: () => Expression;\n    gobbleArray: () => PossibleExpression;\n    throwError: (msg: string) => never;\n}\n```\n\n### License\n\njsep is under the MIT license. See LICENSE file.\n\n### Thanks\n\nSome parts of the latest version of jsep were adapted from the esprima parser.\n","publish_time":1629839347383,"maintainers":[{"name":"soney","email":"swloney@gmail.com"},{"name":"smekkie","email":"ericsmekens@msn.com"},{"name":"leaverou","email":"lea@verou.me"}],"_cnpm_publish_time":1629839347383,"dist-tags":{"beta":"1.3.0-beta.1","latest":"1.6.0"}}