{"_id":"jsep@1.6.0","bugs":{"url":"https://github.com/EricSmekens/jsep/issues"},"dist":{"shasum":"21a1ebd9a4f858e6c58ffd05e3492e31d29fd8b0","tarball":"http://registry-npm.ywwl.com/jsep/download/jsep-1.6.0.tgz","fileCount":16,"integrity":"sha512-Y8Tr54CX7B5YGAwo7/n8eumidEX3Opx98RyyQVnlHqUaZcPA8uUzL2v1rshr9ypW9Q6hNjfJtg3sL+8kaNE7TA==","signatures":[{"sig":"MEUCIQCerJ8Xgc92H771yXOyl7UskkqG4rJEMQKOPNzDTDiGRAIgYLIM2NMITN0IGRMp+tejntRljNmmHbSzJ29rmrCBlAI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIC5PiqFERhJZ1TdoO7C1l+ss0KF6oJrSmTOJZAiEgcz1AiEAnklfePg2yGhFBdLh3Etcz+a3XWoXUJAgqE5Cs4QhEiw="}],"unpackedSize":390287,"size":100040,"noattachment":false,"key":"/jsep/-/jsep-1.6.0.tgz"},"main":"./dist/cjs/jsep.cjs.js","name":"jsep","type":"module","author":{"url":"http://from.so/","name":"Stephen Oney","email":"swloney@gmail.com"},"module":"./dist/jsep.js","engines":{"node":">= 20.16.0"},"exports":{".":{"types":"./typings/tsd.d.ts","default":"./dist/jsep.js","require":"./dist/cjs/jsep.cjs.js"}},"gitHead":"b1f66cb043c12cb63a5dd866a5969b3e78b368e6","license":"MIT","private":false,"release":{"plugins":[["@semantic-release/commit-analyzer",{"preset":"angular","parserOpts":{"noteKeywords":["BREAKING CHANGE","BREAKING CHANGES","BREAKING"]}}],["@semantic-release/release-notes-generator",{"preset":"angular","parserOpts":{"noteKeywords":["BREAKING CHANGE","BREAKING CHANGES","BREAKING"]},"writerOpts":{"commitsSort":["scope","subject"]}}],"@semantic-release/changelog",["@semantic-release/exec",{"prepareCmd":"NEXT_VERSION=${nextRelease.version} pnpm run build"}],["@semantic-release/npm",{"tarballDir":"./"}],["@semantic-release/git",{"message":"build: ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"}],["@semantic-release/github",{"assets":[{"path":"./*.tgz","label":"build"}]}]],"branches":["master",{"name":"alpha","prerelease":true},{"name":"beta","prerelease":true}],"commitPaths":["src/","packages/ternary/src/","types","typings/",".npmignore","package*.json","rollup*.js"]},"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 30000 \"--no-sandbox\" ","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:all && npm run test:all && npm run docco","prepare":"husky install","release":"./release.sh","test:all":"pnpm -r --workspace-concurrency=1 run test","build:all":"pnpm --recursive --workspace-root run build","build:watch":"npx rollup -c --watch","test:performance":"node test/performance.test.js"},"typings":"typings/tsd.d.ts","version":"1.6.0","_npmUser":{"name":"smekkie","email":"ericsmekens@msn.com"},"homepage":"https://ericsmekens.github.io/jsep/","repository":{"url":"git+https://github.com/EricSmekens/jsep.git","type":"git"},"_npmVersion":"10.9.9","description":"a tiny JavaScript expression parser","directories":{"test":"test"},"maintainers":[{"name":"soney","email":"swloney@gmail.com"},{"name":"smekkie","email":"ericsmekens@msn.com"},{"name":"leaverou","email":"lea@verou.me"}],"_nodeVersion":"22.23.3","_hasShrinkwrap":false,"devDependencies":{"docco":"^0.9.1","husky":"^9.1.7","eslint":"^10.12.0","rollup":"^4.64.2","benchmark":"^2.1.4","puppeteer":"^25.12.0","http-server":"^14.1.1","@commitlint/cli":"^21.2.3","node-qunit-puppeteer":"^2.1.2","rollup-plugin-delete":"^3.0.2","rollup-plugin-terser":"^7.0.2","@semantic-release/git":"^9.0.0","semantic-release-plus":"^18.4.1","@rollup/plugin-replace":"^6.0.3","@semantic-release/exec":"^6.0.3","semantic-release-monorepo":"^7.0.5","@commitlint/config-angular":"^21.2.3","@semantic-release/changelog":"^5.0.1"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jsep_1.6.0_1791744919286_0.61061123426477"},"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); // now included by default\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#### Custom Literals\n\nYou can add or remove additional valid literals. By default, only `true`, `false`, and `null` are defined\n```javascript\n// Add standard JS literals:\njsep.addLiteral('undefined', undefined);\njsep.addLiteral('Infinity', Infinity);\njsep.addLiteral('NaN', NaN);\n\n// Remove \"null\" literal from default definition\njsep.removeLiteral('null');\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":1791744919383,"_cnpm_publish_time":1791744919383,"dist-tags":{"beta":"1.3.0-beta.1","latest":"1.6.0"}}