{"id":15025575,"url":"https://github.com/danielxmoore/civet","last_synced_at":"2025-05-13T23:09:43.799Z","repository":{"id":57862903,"uuid":"523497032","full_name":"DanielXMoore/Civet","owner":"DanielXMoore","description":"A TypeScript superset that favors more types and less typing","archived":false,"fork":false,"pushed_at":"2025-04-28T19:56:11.000Z","size":7268,"stargazers_count":1853,"open_issues_count":116,"forks_count":41,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-06T18:23:18.884Z","etag":null,"topics":["coffeescript","javascript","typescript"],"latest_commit_sha":null,"homepage":"https://civet.dev","language":"TypeScript","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/DanielXMoore.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-08-10T21:07:26.000Z","updated_at":"2025-05-01T14:14:02.000Z","dependencies_parsed_at":"2024-03-12T21:29:43.665Z","dependency_job_id":"5a3a6e57-8dfc-4856-bfa6-9cab11aa7fe3","html_url":"https://github.com/DanielXMoore/Civet","commit_stats":{"total_commits":2731,"total_committers":28,"mean_commits":97.53571428571429,"dds":0.5276455510801904,"last_synced_commit":"b1297f8b84baab633f98f3b69841d77343db5829"},"previous_names":[],"tags_count":338,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielXMoore%2FCivet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielXMoore%2FCivet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielXMoore%2FCivet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielXMoore%2FCivet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanielXMoore","download_url":"https://codeload.github.com/DanielXMoore/Civet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254042275,"owners_count":22004887,"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":["coffeescript","javascript","typescript"],"created_at":"2024-09-24T20:02:36.527Z","updated_at":"2025-05-13T23:09:43.747Z","avatar_url":"https://github.com/DanielXMoore.png","language":"TypeScript","readme":"Civet\n=====\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/DanielXMoore/Civet/build.yml?branch=master\u0026logo=github\u0026style=for-the-badge)](https://github.com/DanielXMoore/Civet/actions/workflows/build.yml)\n[![NPM Version](https://img.shields.io/npm/v/@danielx/civet.svg?style=for-the-badge)](https://www.npmjs.com/package/@danielx/civet)\n[![NPM Downloads](https://img.shields.io/npm/dm/@danielx/civet.svg?style=for-the-badge)](https://www.npmjs.com/package/@danielx/civet)\n[![Coverage Status](https://img.shields.io/coverallsCoverage/github/DanielXMoore/Civet?style=for-the-badge)](https://coveralls.io/github/DanielXMoore/Civet?branch=main)\n[![Discord](https://img.shields.io/discord/933472021310996512?style=for-the-badge)](https://discord.com/invite/xkrW9GebBc)\n[![Open Collective](https://img.shields.io/opencollective/all/civet?style=for-the-badge)](https://opencollective.com/civet)\n\nThe modern way to write TypeScript.\n\n- [Documentation](https://civet.dev/)\n- [Changelog](CHANGELOG.md)\n- [Design Philosophy](https://civet.dev/philosophy)\n- [Civet Playground](https://civet.dev/playground)\n- [Civet VSCode Extension](https://marketplace.visualstudio.com/items?itemName=DanielX.civet)\n- [Discord Server](https://discord.gg/xkrW9GebBc)\n- Plugins for\n  [Vite, esbuild, Astro, Farm, Rolldown, Rollup, Webpack](source/unplugin),\n  \u003c!--\n  [esbuild](source/esbuild-plugin.civet),\n  [Vite](https://github.com/edemaine/vite-plugin-civet),\n  --\u003e\n  [ESM/CJS loader](source/esm.civet),\n  [Babel](source/babel-plugin.civet),\n  [Jest](https://github.com/DanielXMoore/Civet/blob/main/integration/jest),\n  [Gulp](integration/gulp),\n  [Bun](source/bun-civet.civet),\n  [`\u003cscript\u003e` tag](https://github.com/DanielXMoore/Civet/tree/main/integration/script)\n- Starter templates for [Solid](https://github.com/edemaine/civet-solid-vite-template) ([older](https://github.com/orenelbaum/solid-civet-template)) and [Solid Start](https://github.com/orenelbaum/solid-start-civet-template)\n\nQuickstart Guide\n---\n\n```bash\n# Install\nnpm install -g @danielx/civet\n# Run Civet code directly in a REPL\ncivet\n# Transpile typed Civet code into TypeScript in a REPL\ncivet -c\n# Compile Civet source file to TypeScript\ncivet \u003c source.civet \u003e output.ts\n# Execute a .civet script\ncivet source.civet ...args...\n# Execute a .civet source file in node\nnode --import @danielx/civet/register source.civet\n```\n\n![image](https://user-images.githubusercontent.com/18894/184558519-b675a903-7490-43ba-883e-0d8addacd4b9.png)\n\nCode Sample\n---\n\n```typescript\nts, {CompilerOptions} from typescript\n\nDefaultCompilerOptions : CompilerOptions :=\n  allowNonTsExtensions: true\n  allowJs: true\n  target: ts.ScriptTarget.Latest\n  moduleResolution: ts.ModuleResolutionKind.NodeJs\n  module: ts.ModuleKind.CommonJS\n  allowSyntheticDefaultImports: true\n  experimentalDecorators: true\n\nfileCache : Record\u003cstring, any\u003e := {}\n\ncreateCompilerHost := (options: CompilerOptions, moduleSearchLocations : string[]) -\u003e\n  fileExists := (fileName: string) : boolean -\u003e\n    fileCache[fileName]?\n\n  readFile := (fileName: string) -\u003e\n    fileCache[fileName]\n```\n\nOverview\n---\n\nCivet is essentially a tasteful superset of TypeScript.\n\n### Implementations of New and Proposed ES Features\n\nSee the [documentation](https://civet.dev/) for examples of these\nand other features.\n\n- Pattern matching (based on [TC39 proposal](https://github.com/tc39/proposal-pattern-matching))\n  - `switch` can match patterns like `[{type: \"text\", name}, ...rest]`\n- Pipe operator (based on [F# pipes](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/symbol-and-operator-reference/#function-symbols-and-operators), [Hack pipes](https://docs.hhvm.com/hack/expressions-and-operators/pipe) and the [TC39 proposal](https://github.com/tc39/proposal-pipeline-operator))\n  - `data |\u003e Object.keys |\u003e console.log` equivalent to\n    `console.log(Object.keys(data))`\n  - Use single-argument arrow functions or `\u0026` shorthand\n    to specify how to use left-hand side\n  - `|\u003e await`, `|\u003e yield`, and `|\u003e return` (at end)\n    for wrapping left-hand side with that operation\n- Short function block syntax like [Ruby symbol to proc](https://ruby-doc.org/core-3.1.2/Symbol.html#method-i-to_proc), [Crystal](https://crystal-lang.org/reference/1.6/syntax_and_semantics/blocks_and_procs.html#short-one-parameter-syntax), [Elm record access](https://elm-lang.org/docs/records#access)\n  - Access: `x.map \u0026.name` or `x.map .name` → `x.map(a =\u003e a.name)`\n  - Nested access + slices: `x.map \u0026.profile?.name[0...3]` → `x.map(a =\u003e a.profile?.name.slice(0, 3))`\n  - Function call: `x.map \u0026.callback a, b` → `x.map($ =\u003e $.callback(a, b))`\n  - Unary operators: `x.map !!\u0026` → `x.map($ =\u003e !!$)`\n  - Binary operators: `x.map \u0026+1` → `x.map($ =\u003e $+1)`\n- Object literal shorthand\n  - `{foo()}` → `{foo: foo()}`, `{props.foo}` → `{foo: props.foo}`\n  - ``{`${x}${y}`: z}`` → ``{[`${x}${y}`]: z}``\n  - `data.{x,y}` or `data{x,y}` → `{x: data.x, y: data.y}`\n  - Flagging shorthand based on [from LiveScript](https://livescript.net/#literals-objects):\n    `{+debug, -live, !verbose}` → `{debug: true, live: false, verbose: false}`\n- Custom infix operators from any two-argument function\n- `do` expressions, `if` expressions, `for` expressions\n\n### Convenience for ES6+ Features\n\n- Const assignment shorthand: `a := b` → `const a = b`, `{a, b} := c` → `const {a, b} = c`\n- Let assignment shorthand: `a .= b` → `let a = b`\n- Typed versions of above: `a: number .= 5` → `let a: number = 5`\n  (but note that `a: number = 5` is the object literal `{a: (number = 5)}`).\n- `@#id` → `this.#id` shorthand for private identifiers\n- `import` shorthand: `x from ./x` → `import x from \"./x\"`\n- Dynamic `import` shorthand: `import './x'` not at top level\n  (e.g. `await import './x'` or inside a function) →\n  `import('./x')`\n- Optional import rename syntax that corresponds to destructuring rename\n  `import {x: y} from \"./z\"` → `import {x as y} from \"./z\"`. You can still\n  use `as` to be compatible with existing ES imports.\n- `export` shorthand: `export x, y` → `export {x, y}`\n- Triple backtick Template Strings remove leading indentation for clarity\n- Class constructor shorthand `@( ... )`\n- ClassStaticBlock `@ { ... }`\n- `\u003c` as `extends` shorthand\n- `///` Block RegExp [like Python re.X](https://docs.python.org/3/library/re.html#re.X)\n\n### JSX Enhancements\n\nInspired by [solid-dsl discussions](https://github.com/solidjs-community/solid-dsl/discussions)\nand [jsx spec issues](https://github.com/facebook/jsx/issues)\n\n- Indentation: instead of explicitly closing `\u003ctag\u003e`s or `\u003c\u003e`s,\n  you can indent the children and Civet will close your tags for you\n- Multiple adjacent elements and/or fragments get automatically\n  combined into a fragment.\n- Arrow function children do not need to be wrapped in braces\n  (assuming they are not preceded by text); this is unambiguous because\n  `\u003e` isn't valid JSX text. For example, `\u003cFor\u003e (item) =\u003e ...`\n  (where function body can be indented).\n- `#foo` shorthand for `id=\"foo\"`;\n  also `#\"foo bar\"`, `` #`foo ${bar}` ``, `#{expr}`\n- `.foo` shorthand for `class=\"foo\"` (but must be at least one space after\n  tag name); also `.foo.bar`, `.\"foo bar\"`, `` .`foo ${bar}` ``, `.{expr}`\n  - `\"civet react\"` flag uses `className` instead of `class`\n- `+foo` shorthand for `foo={true}`, `-foo`/`!foo` shorthand for `foo={false}`\n- Any braced object literal can be used as an attribute:\n  `{foo}` → `foo={foo}`, `{foo: bar}` → `foo={bar}`,\n  `{...foo}` remains as is; methods and getters/setters work too.\n- Attribute `...foo` shorthand for `{...foo}`\n- Attribute values without whitespace or suitably wrapped\n  (parenthesized expressions, strings and template strings,\n  regular expressions, array literals, braced object literals)\n  do not need braces:\n  `foo=bar` → `foo={bar}`, `count=count()` → `count={count()}`,\n  `sum=x+1` → `sum={x+1}`, `list=[1, 2, 3]` → `list={[1, 2, 3]}`\n- Attributes can use computed property names:\n  `[expr]={value}` → `{...{[expr]: value}}`\n- `\"civet solid\"` flag adds correct types for JSX elements and fragments.\n  Use `\"civet solid client\"` (default) for client-only code,\n  `\"civet solid server\"` for server-only code (SSR only), or\n  `\"civet solid client server\"` for isomorphic code that runs on\n  client and server (SSR + hydration).\n- XML comments: `\u003c!-- ... --\u003e` → `{/* ... */}`\n\n### TypeScript Enhancements\n\n- Auto-rewrite `.[mc]ts` → `.[mc]js` in imports (workaround for: https://github.com/microsoft/TypeScript/issues/37582)\n- `:=` readonly class field initializer\n  ```typescript\n    class A\n      x := 3\n  ```\n  ```typescript\n    class A {\n      readonly x = 3\n    }\n  ```\n- Proposal: [Typed Destructuring](https://github.com/DanielXMoore/Civet/discussions/126)\n- Proposal: [Dot Notation for Types](https://github.com/DanielXMoore/Civet/discussions/190)\n- Proposal: [Module Interfaces](https://github.com/DanielXMoore/Civet/discussions/179) https://github.com/microsoft/TypeScript/issues/38511\n- TODO: [Type Declaration Shorthand](https://github.com/DanielXMoore/Civet/issues/176)\n\n### Changes from ES6\n\n- Implicit returns, even for multi-statement functions\n  (avoid by specifying a `void` return type, adding a trailing `;` or\n  explicit `return`, or via the directive `\"civet -implicitReturns\"`)\n- Disallow no parens on single argument arrow function. `x =\u003e ...` must become `(x) =\u003e ...`\n  The reasoning is `x -\u003e ...` =\u003e `x(function() ...)` in CoffeeScript and having `-\u003e` and `=\u003e`\n  behave more differently than they already do is bad. Passing an anonymous function to an\n  application without parens is also convenient.\n- `for(i of x) ...` defaults to const declaration → `for(const i of x) ...`\n- Disallow comma operator in conditionals and many other places. `if x, y` is not allowed. But `for i = 0, l = a.length; i \u003c l; i++, i *= 2` is allowed.\n- Comma operator in `case`/`when` instead becomes multiple conditions.\n- Numbers can't end with a dot (otherwise would be ambiguous with CoffeeScript slices `y[0..x]`). This also implies that you can't access properties\nof numbers with `1..toString()` use `1.toString()` instead. When exponent follows a dot it is treated as a property access since an exponent\ncould be a valid property `1.e10` → `1..e10`. The workaround is to add a trailing zero `1.0e10` or remove the dot before the exponent `1e10`.\n- Additional reserved words `and`, `or`, `loop`, `until`, `unless`\n- Experimental decorator syntax is `@@` instead of `@` because `@` is premium real estate and `@id` → `this.id`, and `@` is also static fields/methods, etc.\n  ```\n  @@classDecorator\n  class X\n    @@methodDecorator\n    method() {}\n  ```\n- `when` inside switch automatically breaks and adds block scope.\n- `else` inside switch adds block scope.\n- No whitespace between unary operators and operands. Mandatory whitespace between condition and ternary `?` ex. `x ? a : b` since `x?` is the unary existential operator.\n- Labels written `:label` (except for special case `$:` for Svelte)\n\n### Scripting Improvements\n\n- Shebang line is kept unmodified in output\n  ```civet\n  #!./node_modules/.bin/ts-node\n  console.log \"hi\"\n  ```\n\n### Comparison to CoffeeScript\n\nTake a look at this [detailed Civet // CoffeeScript comparision](./notes/Comparison-to-CoffeeScript.md)\n\n### Directives\n\nCivet is not just one language; it can be configured in a variety of ways\nvia directives to add or remove language features, or improve behavior\nin certain environments.\nSee [config documentation](https://civet.dev/config).\n\n### Using Civet in your Node.js Environment\n\nYou have now been convinced that Civet is right for your current/next project. Here is how\nto set up your environment to get productive right away and have a Good Time℠.\n\n### Testing\n\nCode coverage with [c8](https://github.com/bcoe/c8) \"just works\" thanks to their source map\nintegration and Civet's source maps.\n\n#### c8 + Mocha\n\n`package.json`\n```json\n  \"scripts\": {\n    \"test\": \"c8 mocha\",\n    ...\n  },\n  \"c8\": {\n    \"extension\": [\n      \".civet\"\n    ]\n  },\n  \"mocha\": {\n    \"extension\": [\n      \"civet\"\n    ],\n    \"loader\": [\n      \"@danielx/civet/esm\"\n    ],\n    ...\n  ...\n```\n\n\u003c!--\n`ts-node` must be configured with `transpileOnly` (it can't resolve alternative extensions). Also I think `module` needs to be at least `ES2020` for the Civet ESM loader to work.\n\n`tsconfig.json`\n```json\n  ...\n  \"ts-node\": {\n    \"transpileOnly\": true,\n    \"compilerOptions\": {\n      \"module\": \"ES2020\"\n    }\n  }\n```\n--\u003e\n\nIf you don't care for code coverage you can skip c8 (but it is so easy why not keep it?).\n\nYou can also add `.js` and `.ts` extensions if you want to mix and match! Even `.coffee` will work if you require `coffeescript/register` or add a loader for it.\n\nExecute the tests\n\n```bash\nyarn test\n```\n\nStep 4: Enjoy!\n\n### Developing\n\nUse the alpha version of [Civet Language Server](https://marketplace.visualstudio.com/items?itemName=DanielX.civet)\n\nThe language server provides syntax highlighting, completions, hover documentation, symbols outline, red squigglies, and go to definition.\n\n---\n\n*Q?* Why can't I just use the built-in VSCode TypeScript LSP?\n\n*A:* VSCode's built in TypeScript LSP can't resolve non `.ts/.js`, not even with plugins. Maybe one day they'll allow for\nplugins that let you adjust the resolver and insert a transpilation step but until then a separate language server is necessary.\n\n---\n\n*Q?* Sometimes the file outline disappears and the red squigglies are all in the wrong place and maybe a notification pops up\nabout some kind of LSP error.\n\n*A:* I'm sorry that happened to you but the Civet Language Server is still alpha and improving rapidly. Please let me know\nexactly what happened and I'll try to do better next time.\n\nIt may happen when there is a syntax error in your Civet file. You can check and see if it compiles using the CLI tool in the meantime.\n\nPlease do submit bug reports / feature requests.\n\n### Building\n\nI strongly recommend using [esbuild](https://esbuild.github.io/) for building / packaging your Civet project.\n\n```javascript\nimport esbuild from 'esbuild'\nimport civetPlugin from '@danielx/civet/esbuild-plugin'\n\nesbuild.build({\n  ...,\n  plugins: [\n    civetPlugin\n  ]\n}).catch(() =\u003e process.exit(1))\n```\n\nIt's super fast and works great!\n\nCode Coverage\n---\n\n[![Coverage Status](https://coveralls.io/repos/github/DanielXMoore/Civet/badge.svg?branch=main)](https://coveralls.io/github/DanielXMoore/Civet?branch=main)\n\nSponsorship\n---\nIf you are so inclined, you can sponsor Civet on [Open Collective](https://opencollective.com/civet).\n","funding_links":["https://opencollective.com/civet"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielxmoore%2Fcivet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielxmoore%2Fcivet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielxmoore%2Fcivet/lists"}