{"_id":"@anche/textmate-utilities","_rev":"2-efcccddfe812db1ca511bfbcf525a1b6","name":"@anche/textmate-utilities","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@anche/textmate-utilities","version":"0.0.1","description":"TextMate Grammar Parser","main":"lib/index.js","module":"lib/index.es.js","types":"lib/textmate-utilities/src/index.d.ts","keywords":["textmate","tmtheme","grammar","parser"],"author":{"name":"Angelo Abdoelsamath","email":"angelo.a@me.com"},"homepage":"https://github.com/el-angel/theme-editor#readme","license":"MIT","directories":{"lib":"lib","test":"__tests__"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"repository":{"type":"git","url":"git+https://github.com/el-angel/theme-editor.git"},"scripts":{"test":"jest","test:watch":"jest --watch","clean":"rimraf ./lib ./esm","prebuild":"yarn clean","build":"rollup -c","prepack":"yarn build","watch":"rollup --watch -c","typecheck":"tsc --noEmit","lint":"eslint src --ext .ts,.tsx .","precommit":"yarn test && tsc --noEmit --composite false && lint-staged"},"lint-staged":{"src/**/*.{ts,tsx}":["pretty-quick --staged","eslint --fix"]},"bugs":{"url":"https://github.com/el-angel/theme-editor/issues"},"dependencies":{"@anche/shared":"^1.0.0","monaco-textmate":"^3.0.1","onigasm":"^2.2.4"},"devDependencies":{"@rollup/plugin-commonjs":"^14.0.0","@rollup/plugin-node-resolve":"^8.4.0","@types/jest":"^26.0.8","@zerollup/ts-transform-paths":"^1.7.18","jest":"^26.2.2","rimraf":"^3.0.2","rollup":"^2.22.1","rollup-plugin-typescript2":"^0.27.1","ts-jest":"^26.1.4","ttypescript":"^1.5.10"},"gitHead":"1761a7da1b5654f62db95a0bb69a1592911b086c","_id":"@anche/textmate-utilities@0.0.1","_nodeVersion":"12.14.1","_npmVersion":"lerna/3.22.0/node@v12.14.1+x64 (darwin)","dist":{"integrity":"sha512-n3CiYUYYpvAH1ppL72MOLKZzBxoEqCtxkhif7OGy7rKnfHuRQqFJjHiom/TLKOR/BQylAHNh2HO75rrrCkFZlA==","shasum":"d7318434c1e33583400d8df938457b493bd22694","tarball":"https://registry.npmjs.org/@anche/textmate-utilities/-/textmate-utilities-0.0.1.tgz","fileCount":21,"unpackedSize":40767,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfKx1YCRA9TVsSAnZWagAA3XYP/iHiIDBejNHjEBYsFkd1\nOjO8+vW4OkYpJZGqDc1dt4kz/2PZvpG6pH/ifHXYuzq/FONebvijkVblVJ3e\nQwMvNBnQ+IrwF3SHpT7LzONihkP0tuApmauyADG6Tgd97z9hb9f2DNlK0930\nqlzQ5SZCF3Rn9CUeTLUNT26ziJ0i7cei4GU1tyHOHqcs+Sd1KHn/VIHcdkhw\ngLe9InT/5J7bTRNTS+gyt0bMRhMxwN6vYFphoO2JV2vOtOt8cG/NXrSF2nPM\nhF3u/CfNgGoF6/huqYVFtL4svGrGNzMtabMvEU4jOnt+rLQA08AFuOrcvIOo\nuOwakAjtMVi/wlHXt+Za90cSwY7KenBhHDq+FJ+p+hG4Eaiv5yp2UeNAXTM3\nA6UTBbU77+LgEyz338zlUeaapDVrt4atcE+VzWCukKhlkvufey6/7rEUpCVq\nfQv2jNrUCobi6vay6Aa9igwnftFxcZsJtm0TdLJi2zFu9egfaZ4TtdfHEwaH\n9S05DVyk3rHH1IQjfPHBxtcoM7YnfptAT5anI7xLhqn0FDp85KTH5caluDxW\neHLiyH6XgwJhgDcaSjZGtBN6XawiNnX1THfczn5C/zDwRNFd7q/CpsPe0NzS\n6M9A7aVKWMwwPdz618u9oz7ycXivChsXkklTymBxtBH3zJ9kTOv2cQkTZl7w\n2NC8\r\n=9YWQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDkhnLw35W+X6cxl47XByGkt9KVmdyYDM5qKxY7pSfZzgIhAJH41mtNM0ibqOpTwBqWoxE7Bkb+zh0eUk4WpTQfd261"}]},"maintainers":[{"name":"godlevel","email":"angelo.a@me.com"}],"_npmUser":{"name":"godlevel","email":"angelo.a@me.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/textmate-utilities_0.0.1_1596661080268_0.831475929739425"},"_hasShrinkwrap":false},"0.0.2":{"name":"@anche/textmate-utilities","version":"0.0.2","description":"TextMate Grammar Parser","main":"lib/index.js","module":"lib/index.es.js","types":"lib/textmate-utilities/src/index.d.ts","keywords":["textmate","tmtheme","grammar","parser"],"author":{"name":"Angelo Abdoelsamath","email":"angelo.a@me.com"},"homepage":"https://github.com/el-angel/theme-editor#readme","license":"MIT","directories":{"lib":"lib","test":"__tests__"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"repository":{"type":"git","url":"git+https://github.com/el-angel/theme-editor.git"},"scripts":{"test":"jest","test:watch":"jest --watch","clean":"rimraf ./lib ./esm","prebuild":"yarn clean","build":"rollup -c","prepack":"yarn build","watch":"rollup --watch -c","typecheck":"tsc --noEmit","lint":"eslint src --ext .ts,.tsx .","precommit":"yarn test && tsc --noEmit --composite false && lint-staged"},"lint-staged":{"src/**/*.{ts,tsx}":["pretty-quick --staged","eslint --fix"]},"bugs":{"url":"https://github.com/el-angel/theme-editor/issues"},"dependencies":{"monaco-textmate":"^3.0.1","onigasm":"^2.2.4"},"devDependencies":{"@rollup/plugin-commonjs":"^14.0.0","@rollup/plugin-node-resolve":"^8.4.0","@types/jest":"^26.0.8","@zerollup/ts-transform-paths":"^1.7.18","jest":"^26.2.2","rimraf":"^3.0.2","rollup":"^2.22.1","rollup-plugin-typescript2":"^0.27.1","ts-jest":"^26.1.4","ttypescript":"^1.5.10"},"gitHead":"856189d1ee79de64a7fc0072711907d24ba5d62c","_id":"@anche/textmate-utilities@0.0.2","_nodeVersion":"12.14.1","_npmVersion":"lerna/3.22.0/node@v12.14.1+x64 (darwin)","dist":{"integrity":"sha512-Z2Wp5aiuNJS+HYIdeHGN+hPe/W8G2pDrfCUk5VOAPvYC/pY+ltxYiBVYoModU9eOwtbYgHcwQmGDmef9aZe2og==","shasum":"fd1e33f2755cd8497bfdac1d28ffedb8f6d26f9c","tarball":"https://registry.npmjs.org/@anche/textmate-utilities/-/textmate-utilities-0.0.2.tgz","fileCount":21,"unpackedSize":40732,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfMr9dCRA9TVsSAnZWagAAPkwP/ief9j9jmCK6tq/dWNgx\nDmo+nBRbNS1Z6h+xVtEaYlmcv9vZJchxqY4JLkaYAt9nusSfJVfljPqh01ac\nO0q1eSvsj+Vq6f3CHJzuwGyzLmAseGPujrhvO7EiWZYestA8OBmLrvzj2/jW\n+yacoSmJ/9R7eYutVqIcworAPzBYhBbC4aMNWKrX50nl8jerd0YBTEuGY2X1\nbPEwTbreZix5oGQOep8xkai1R6YRRyZZGjJViyfml0SeZY/ZYmwdQqXvaKbd\nKEwKYDyVewiK9VFcSlC6g5T9sxlp5eZ6ceE/5epSYpZrxPNJB9he8kPXc8Jy\np13Mq5hKQmmqhZbX6U515SA5jj3Sn8KQE5YM4xw/SZ20XPMcVCR+Sa8cqkkh\nBSsGzfH8G2O0iezFZXb2tXan54wPSV36HO7CsVk7kHkYi080+nylQOTJb12I\nNniUU4nTOpZykqSYVZXuQcAh70yyJFoZCHgonoJ7oV5NSwx8atISXEW88W0Y\nmIdBHtoqJfFrojTk9FFgPHjNss3hDmYiLkw3GtQl9jtjRvpb+WGXeeBcUkUd\nR0tkIhDkcc7k0a2alCOxCRFJz4YCRw78iVXTRrabibXVmd/YT9XH1/xvp5PM\nvOg+RcQAYX36zgBatZaDVquMnyTYbvGIE7yjAzC5Oalliyj7cAFBP6AD4GYi\nsQyD\r\n=ZZP6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD7et49zDII1z7cUQJmf5stcG/UTFAIgqolLLS7x8uA6wIgPO/Iba2rQj0qKNXJQHtJ1kw04QEnRLMaY7zTs9FfokQ="}]},"maintainers":[{"name":"godlevel","email":"angelo.a@me.com"}],"_npmUser":{"name":"godlevel","email":"angelo.a@me.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/textmate-utilities_0.0.2_1597161308926_0.6724787984097875"},"_hasShrinkwrap":false}},"time":{"created":"2020-08-05T20:57:59.993Z","0.0.1":"2020-08-05T20:58:00.393Z","modified":"2022-04-04T13:56:51.015Z","0.0.2":"2020-08-11T15:55:09.064Z"},"maintainers":[{"name":"godlevel","email":"angelo.a@me.com"}],"description":"TextMate Grammar Parser","homepage":"https://github.com/el-angel/theme-editor#readme","keywords":["textmate","tmtheme","grammar","parser"],"repository":{"type":"git","url":"git+https://github.com/el-angel/theme-editor.git"},"author":{"name":"Angelo Abdoelsamath","email":"angelo.a@me.com"},"bugs":{"url":"https://github.com/el-angel/theme-editor/issues"},"license":"MIT","readme":"# `textmate-utilities`\n\nThis package exposes several utilities that help with TextMate Scopes.\n\n```typescript\n// types\ninterface Position {\n    line: number;\n    start: number;\n    length: number;\n}\n\ninterface CodeDocument {\n    getTextAtPosition(position: Position): string;\n    getLines(): string[];\n    getRaw(): string;\n}\n\ninterface TextMateNode extends Position {\n    scopes: Scope[];\n}\n\ninterface TextMateParserResult {\n    code: CodeDocument;\n    tokens: TextMateNode[];\n}\n```\n\n## Usage\n\nFirst copy the following files into your applications static folder (which should be accessable via `window.fetch`):\n\n-   all the wanted grammar files from `./node_modules/@anche/textmate-utilities/grammar` (or add your own, can be json or plist)\n-   `onigasm.wasm` (https://github.com/NeekSandhu/onigasm), also in `./node_modules/lib/onigasm.wasm`\n\nBefore you can use the helper, you should bootstrap your app with the initialize module\n\n```typescript\nimport { initialize } from '@anche/textmate-utilities';\n\nconst ONIGASM_URL = '/public/static/onigasm.wasm';\n\n(async () => {\n    await initialize(ONIGASM_URL);\n    App.start();\n})();\n```\n\n### TextMateScopesParser setup\n\n```typescript\nimport { TextMateScopesParser } from '@anche/textmate-utilities';\n\nconst service = new TextMateScopesParser({\n    filePaths: {\n        // [languageScope]: 'path to your static grammar file'\n        'source.tsx': '/grammar/TypeScriptReact.tmLanguage.json',\n    },\n});\n\nconst rawCode = `\n  import React from 'react';\n\n  interface Props {\n    onClick: () => void;\n  };\n\n  const Button: React.FC<Props> = ({ onClick, children }) => {\n    return (\n      <button type=\"button\" onClick={onClick}>\n        {children}\n      </button>\n    );\n  };\n\n  export default Button;\n`;\n\nconst code = service.parse(rawCode, 'source.tsx' /* key of filePaths: languageScope */);\n```\n\n### Rule/Scope matching\n\nThis utility helps by getting the applicable rule for a given scope\n\n```typescript\nimport { match } from '@anche/textmate-utilities';\n\ninterface TextMateRule {\n    scopes: string[];\n}\n\ntype MatchFn = <T extends TextMateRule>(nodeScopes: string | string[], rules: T[]) => T | null;\n\nconst rawCode = `import React from 'react';`;\n\nconst parsed: { code: CodeDocument; tokens: TextMateNode[] } = service.parse(rawCode, 'source.tsx');\n\n/**\n * the node of `import`, object will look like this:\n * {\n *   line: 0,\n *   start: 0,\n *   length: 6\n *   scopes: [\n *      'keyword.control.import.tsx',\n *      'meta.import.tsx',\n *      'source.tsx',\n *   ],\n * }\n */\nconst firstNode = parsed.tokens[0];\n\n// Defined TextMate Rules\nconst textMateRules = [\n    { scopes: ['source.tsx', 'keyword.control.import.tsx'], color: '#000000' },\n    { scopes: ['meta.var.expr.tsx', 'meta.block.tsx'], color: '#ffffff' },\n    { scopes: ['meta.tag entity'], color: '#ff00ff' },\n];\n\n// Now you want to know which color the `import` text should be based on your rules, so you need to find out if a rule applies and which one that is:\nconst rule = match(firstNode.scopes, textMateRules);\n\n// rule = textMateRules[0];\n```\n","readmeFilename":"README.md"}