{"id":20503856,"url":"https://github.com/phcode-dev/language-support","last_synced_at":"2025-10-26T19:07:52.526Z","repository":{"id":234449331,"uuid":"788919636","full_name":"phcode-dev/language-support","owner":"phcode-dev","description":"Language intelligence features for phoenix code","archived":false,"fork":false,"pushed_at":"2025-03-04T03:57:20.000Z","size":811,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-04T09:30:46.999Z","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":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phcode-dev.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":"2024-04-19T10:51:19.000Z","updated_at":"2024-08-26T20:25:00.000Z","dependencies_parsed_at":"2024-04-24T11:48:02.923Z","dependency_job_id":null,"html_url":"https://github.com/phcode-dev/language-support","commit_stats":null,"previous_names":["phcode-dev/language-support"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phcode-dev%2Flanguage-support","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phcode-dev%2Flanguage-support/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phcode-dev%2Flanguage-support/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phcode-dev%2Flanguage-support/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phcode-dev","download_url":"https://codeload.github.com/phcode-dev/language-support/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241825921,"owners_count":20026593,"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-11-15T19:34:41.157Z","updated_at":"2025-10-26T19:07:47.488Z","avatar_url":"https://github.com/phcode-dev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Phoenix language-support\n\nThis library provides the language intelligence for CSS/LESS/HTML etc...\n\n\u003c!-- TOC --\u003e\n* [Phoenix Language Intelligence](#phoenix-language-intelligence)\n  * [Installation](#installation)\n    * [Getting the code locally](#getting-the-code-locally)\n    * [Usage in browser](#usage-in-browser)\n    * [Usage in web-worker in browser](#usage-in-web-worker-in-browser)\n  * [Development](#development)\n  * [Tests in Browser](#tests-in-browser)\n    * [Debug Symbols in tests.](#debug-symbols-in-tests)\n    * [Publishing to npm](#publishing-to-npm)\n\u003c!-- TOC --\u003e\n\n## Installation\nThe library can be either installed using npm or using the CDN link (See usage in browser below ).\n\n### Getting the code locally\nInstall the library can be downloaded locally with the following command:\n\n```bash\nnpm install @phcode/fs\n```\n\nOnce installed, the `language-worker.js` lib will be present in the following location\n```bash\n\u003cproject_root\u003e/node_modules/@phcode/language-support/dist/language-worker.js\n```\n### Usage in browser\nThis library can only be run in a web worker.\n\n### Usage in web-worker in browser\nInside your web-worker, import the library as below.\n```js\nimportScripts('\u003cproject_root\u003e/node_modules/@phcode/language-support/dist/language-worker.js');\n// OR from CDN directly as\nimportScripts('https://unpkg.com/@phcode/language-support@latest/dist/language-worker.js');\n```\n\n## Development\nThis segment is dedicated to those contributing or modifying the codebase of this repository.\nIf you are just using this as a library, please skip this section.\n\nTo build it:\n\n```bash\nnpm install\nnpm run build\n```\n\nThe `npm run build` command will create two files `dist/language-worker.js` and `dist/language-worker-debnug.js`.\n\n## Tests in Browser\nWhile developing, use test script to open browser tests.\n* Test runs tests against the built artifacts in dist folder.\n* You should `npm run build` if any changes were made to the src folder\n```bash\nnpm run build\nnpm run test-browser\n```\n\nNOTE: you can also use `npm run serve` to also start a web server for development.\n\n### Debug Symbols in tests.\nBy default, tests are run against the release build `test/virtualfs.js`. As it is heavily optimized it might be hard to debug with the release lib. \n\nIf you want to debug the tests with more debug symbols, search for `\u003cscript src=\"virtualfs-debug.js\"\u003e\u003c/script\u003e` in file `test/index.html` and follow steps there.\n\n### Publishing to npm\n\nInorder to publish the package to npm, do the following\n\n1. run `npm run relese` and push changes to main branch.\n2. raise a pull request from `main` branch to `npm` branch. Once the pull request is merged\nand the code pushed to npm branch, GitHub actions will automatically publish the library to npm.\n\n## API\n\nBelow is a markdown documentation for the `CSSLanguageService` object, detailing its functions and usage. This can be used as part of a project's documentation, README, or developer guide.\n\n---\n\n## CSSLanguageService API\n\nThe `CSSLanguageService` provides utility functions for parsing CSS and\nretrieving CSS selectors(document symbols such as classes, IDs, and other selectors) from given text content.\n\n### Methods\n\n### `getAllSymbols(text, cssMode, filePath)`\n\nRetrieves all CSS selectors from the provided CSS text as an array of strings.\n\n**Parameters**:\n\n- `text` (`string`): The CSS code to analyze.\n- `cssMode` (`string`): The mode of the CSS document. This should correspond to one of the supported CSS modes (e.g., CSS, SCSS, LESS) defined in `CSS_MODES`.\n- `filePath` (`string`): Optional. The path of the CSS file, used for resolving relative URLs within the CSS. Defaults to `\"file://placeholder.css\"`.\n\n**Returns**:\n\n- `Array[string]`: An array containing all the CSS selectors found in the document.\n\n**Example Usage**:\n\n```javascript\nconst cssText = \".class { color: red; } #id { margin: 10px; }\";\nconst selectors = CSSLanguageService.getAllSymbols(cssText, CSSLanguageService.CSS_MODES.CSS);\nconsole.log(selectors); // Output: [\".class\", \"#id\"]\n```\n\n### `validateCSS(text, cssMode, filePath, lintSettings)`\n\nValidates CSS code using specified settings and returns an array of diagnostic messages.\n\n**Parameters:**\n\n- `text` (string): The CSS code to be validated.\n- `cssMode` (string): The CSS mode used for parsing the code.\n- `filePath` (string): The path of the CSS file being validated.\n- `lintSettings` (object): The lint settings to be used for validation.\n\n  Possible keys and their descriptions:\n  - `compatibleVendorPrefixes`: Unnecessary vendor prefixes checker.\n  - `vendorPrefix`: Warns on missing vendor prefixes.\n  - `duplicateProperties`: Flags duplicated CSS properties.\n  - `emptyRules`: Detects CSS rules that have no properties.\n  - `importStatement`: Flags the use of @import within CSS files.\n  - `boxModel`: Warns if CSS box model is potentially misused.\n  - `universalSelector`: Warns against the use of the universal selector (*).\n  - `zeroUnits`: Warns when units specification for zero values is unnecessary.\n  - `fontFaceProperties`: Ensures necessary properties are included in @font-face declarations.\n  - `hexColorLength`: Enforces consistency in hex color definitions.\n  - `argumentsInColorFunction`: Validates arguments within color functions.\n  - `unknownProperties`: Warns on unrecognized or mistyped CSS properties.\n  - `ieHack`: Warns about CSS hacks for older versions of Internet Explorer.\n  - `unknownVendorSpecificProperties`: Flags vendor-specific properties that might not be universally recognized.\n  - `propertyIgnoredDueToDisplay`: Notifies when CSS properties are ignored due to the `display` setting of an element.\n  - `important`: Warns against the excessive use of `!important`.\n  - `float`: Advises on the use of `float`, recommending modern layout alternatives.\n  - `idSelector`: Advises against using ID selectors for styling.\n\nEach key's value can be \"warning\" or \"error\".\n\n**Return Value:**\n\nReturns an `Array` of objects with the following properties:\n- `code` (string)\n- `source` (string)\n- `message` (string)\n- `severity` (number)\n- `range` (object) which includes:\n  - `start` (object): contains `line` (number) and `character` (number)\n  - `end` (object): contains `line` (number) and `character` (number)\n\nThese objects represent the diagnostic messages produced during validation.\n\n### Constants\n\n#### `CSSLanguageService.CSS_MODES`\n\nDefines the supported CSS modes for the `getAllSymbols` function. Includes:\n\n- `CSS`: Standard CSS.\n- `SCSS`: Sassy CSS (SCSS).\n- `LESS`: Leaner Style Sheets (LESS).\n\n**Example**:\n\n```javascript\nconsole.log(CSSLanguageService.CSS_MODES.CSS); // Output: \"CSS\"\n```\n\n## HTMLLanguageService API\n\nThe `HTMLLanguageService` provides utility functions for parsing and operating on HTML/PHP/HTML Like content.\n\n### Methods\n\n#### `getAllDocumentLinks(text, htmlMode, filePath)`\n\nExtracts all links from the provided HTML text.\n\n**Parameters**:\n\n- `text` (`string`): The CSS code to analyze.\n- `cssMode` (`string`): The mode of the HTML document. This should correspond to one of the supported HTML modes (e.g., HTML, PHP, XHTML, HTM) defined in `HTML_MODES`.\n- `filePath` (`string`): Optional. The path of the html file, used for resolving relative URLs within the CSS. Defaults to `\"file:///placeholder.html\"`.\n\n**Returns**:\n\n- `Array[string]`: An array containing all the html links found in the document.\n\n**Example Usage**:\n\n```javascript\nconst htmlContent = `\u003ca href=\"http://example.com\"\u003eVisit Example\u003c/a\u003e`;\nconst links = HTMLLanguageService.getAllDocumentLinks(htmlContent,\n        HTMLLanguageService.HTML_MODES.HTML, \"file:///your-path.html\");\nconsole.log(links); // Output: [\"http://example.com\"]\n```\n\n### Constants\n\n#### `CSSLanguageService.HTML_MODES`\n\nDefines the supported HTML modes. Includes:\n\n- `HTML`: Standard HTML documents.\n- `XHTML`: XHTML documents.\n- `HTM`: HTM files, commonly an alternate extension for HTML files.\n- `PHP`: PHP files that contain HTML content.\n\n**Example**:\n\n```javascript\nconsole.log(HTMLLanguageService.HTML_MODES.HTML); // Output: \"HTML\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphcode-dev%2Flanguage-support","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphcode-dev%2Flanguage-support","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphcode-dev%2Flanguage-support/lists"}