# @eeue56/derw

> An Elm-inspired language that transpiles to TypeScript

Latest version **0.0.3-7** (published 2021-12-31) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @eeue56/derw
pnpm add @eeue56/derw
yarn add @eeue56/derw
bun add @eeue56/derw
```

Provides the command `derw`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3-7 |
| Published | 2021-12-31 |
| First published | 2021-12-13 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 464.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 383 |
| Author | eeue56 |
| Maintainers | eeue56 |
| Keywords | typescript, hiraeth |

## Links

- npm: https://www.npmjs.com/package/@eeue56/derw
- Repository: https://github.com/eeue56/derw
- Homepage: https://github.com/eeue56/derw#readme
- Issues: https://github.com/eeue56/derw/issues
- npm.io page: https://npm.io/package/@eeue56/derw

## Dependencies (5)

- [typescript](https://npm.io/package/typescript.md) ^4.3.5
- [@eeue56/bach](https://npm.io/package/@eeue56/bach.md) ^0.0.10
- [@eeue56/baner](https://npm.io/package/@eeue56/baner.md) ^0.0.2
- [@eeue56/adeilad](https://npm.io/package/@eeue56/adeilad.md) ^0.0.1
- [@eeue56/ts-core](https://npm.io/package/@eeue56/ts-core.md) ^1.1.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.3-7 (latest) — 2021-12-31
- 0.0.3-6 — 2021-12-31
- 0.0.3-5 — 2021-12-31
- 0.0.3-4 — 2021-12-30
- 0.0.3-3 — 2021-12-28
- 0.0.3-2 — 2021-12-28
- 0.0.3-1 — 2021-12-13
- 0.0.3-0 — 2021-12-13
- 0.0.2-0 — 2021-12-13

## README

# derw

An Elm-inspired language that transpiles to TypeScript

# Usage

```bash
npx @eeue56/derw

To get started:
Start a package via `derw init`
Compile via `derw compile`
Or compile and test via `derw test`
```

You can run the derw compiler via npx. You must provide files via `--files` or be in a package directory.

```bash
npx @eeue56/derw

Let\'s write some Derw code
To get started:
Provide entry files via --files
Or run me without args inside a package directory
  --files [string...]:      Filenames to be given
  --test :                  Test the project
  --target ts | js | derw:  Target TS, JS or Derw output
  --output string:          Output directory name
  --verify :                Run typescript compiler on generated files to ensure valid output
  --debug :                 Show a parsed object tree
  --only string:            Only show a particular object
  --run :                   Should be run via ts-node/node
  --format :                Format the files given in-place
  --quiet :                 Keep it short and sweet
  -h, --help :              This help text
```

# Example

You can find a bunch of examples in [examples](./examples), along with the Typescript they generate. But the general gist is: Elm-compatible syntax where possible.

```elm
type Result a b
    = Err { error: a }
    | Ok { value: b }

asIs : Result a b -> Result a b
asIs result =
    case result of
        Err { error } -> Err { error }
        Ok { value } -> Ok { value }
```

# Roadmap

## 0.0.1 alpha

-   [x] Arrays `[ ]`, `[ 1, 2, 3 ]`, `[ [ 1, 2, 3 ], [ 3, 2, 1 ] ]`
-   [x] Booleans `true`, `false`
-   [x] Boolean equality `1 < 2`, `1 <= 2`, `1 == 2`, `1 != 2`, `1 > 2`, `1 >= 2`
-   [x] Boolean operations `true && false`, `not true`, `true || false`
-   [x] Strings `""`, `"hello world"`
-   [x] Format strings ` `` `, `` `Hello ${name}` ``
-   [x] Numbers `-1`, `0`, `1`, `-1.1`, `1.1`
-   [x] Addition `1 + 2`, `"Hello" + name`
-   [x] Subtraction `2 - 1`
-   [x] Multiplication `2 * 1`
-   [x] Division `2 / 1`
-   [x] Pipe `[1, 2, 3] |> List.fold add`, `List.fold add <| [1, 2, 3]`
-   [ ] Compose `>>`, `<<`
-   [x] Constants `hello = "hello world"`
-   [x] Function definitions
-   [x] Lists `[ 1, 2, 3 ]`, `[ "hello", "world" ]`
-   [x] List ranges `[ 1..5 ]`, `[ start..end ]`

```elm
add : number -> number -> number
add x y = x + y
```

-   [x] Function calls

```elm
three = add 1 2
```

-   [x] Module references

```elm
three = List.map identity [ 1, 2, 3 ]
```

-   [x] Union types

```elm
type Result a b
    = Err { error: a }
    | Ok { value: b }
```

-   [x] Type variables

```
type Thing a = Thing a
```

-   [x] Type aliases

```elm
type User =
    { name: string }
```

-   [x] Object literals

```elm
user: User
user = { name: string }
```

-   [x] Imports

```elm
import List
import Result exposing ( map )
import something as banana
```

-   [x] Exports

```elm
exposing ( map )
```

-   [x] Let statements

```elm
sayHiTo : User -> string
sayHiTo user =
    let
        name = user.name
    in
        "Hello " + name

sayHelloTo : User -> string
sayHelloTo user =
    let
        getName: User -> string
        getName user = user.name
    in
        "Hello" + getName user
```

-   [x] If statements

```elm
type Animal = Animal { age: number }
sayHiTo : Animal -> string
sayHiTo animal =
    if animal.age == 1 of
        "Hello little one!"
    else
        "You're old"
```

-   [x] Case..of

```elm
type Animal = Dog | Cat
sayHiTo : Animal -> string
sayHiTo animal =
    case animal of
        Dog -> "Hi dog!"
        Cat -> "Hi cat!"
```

-   [x] Destructing in case..of

```elm
type User = User { name: string }

sayHiTo : User -> string
sayHiTo user =
    case user of
        User { name } -> "Hi " + name + !"
```

-   [x] strings in case..of
-   [x] defaults in case..of

```elm
sayHiTo : string -> string
sayHiTo name =
    case name of
        "Noah" -> "Hi " + name + !"
        default: "I don't know you"
```

-   [ ] List destructing

```elm

sayHiTo : List number -> string
sayHiTo xs =
    case xs of
        [] -> "Empty"
        x::ys -> "Hello " + x + (sayHiTo ys)
```

-   [x] Constructing union types

```elm
type User = User { name: string }
noah = User { name: "Noah" }
```

-   [x] Errors on type name collison

````markdown
The name `Person` has been used for different things.
8 - 10:

```
type Person =
    Person { name: string }
```

11 - 14:

```
type alias Person = {
    name: string
}
```
````

-   [x] Errors on function name collison

````markdown
The name `isTrue` has been used for different things.
0 - 3:

```
isTrue: boolean -> boolean
isTrue x =
    x == true
```

4 - 7:

```
isTrue: boolean -> boolean
isTrue x =
    x != true
```
````

-   [x] Some form of basic type errors

````markdown
Failed to parse examples/errors/mismatching_types.derw due to:
Error on lines 0 - 3
Expected `boolean` but got `number` in the body of the function:

```
isTrue: boolean -> boolean
isTrue x =
    1 + 2
```

Error on lines 4 - 7
Expected `List string` but got `List number`:

```
names: List string
names =
    [1..2]
```
````

-   [x] lambdas `\x -> x + 1`, `\x y -> x + y`
-   [x] Typescript output
-   [x] Javscript output
-   [ ] Elm output
-   [x] Module resolution
-   [x] CLI
-   [x] Basic type checking
-   [x] Detect if types exist in current namespace
-   [x] Syntax highlighting for editors
-   [x] Collision detection for names in a module
-   [x] Importing of Derw files

```elm
import "./other"
import "./something" as banana
import "./another" exposing ( isTrue, isFalse )
```

-   [x] Errors when failing to find relative import

```
Warning! Failed to find `examples/derw_imports/banana` as either derw, ts or js
```

-   [x] Single line comments

```elm
-- hello
isTrue: boolean -> boolean
isTrue x =
    x
```

-   [x] Single line comments in function or const bodies

```elm
isTrue: boolean -> boolean
isTrue x =
    -- hello
    x
```

-   [x] Multiline comments

```elm
{-
hello
world
-}
isTrue: boolean -> boolean
isTrue x =
    x
```

-   [x] Function arguments

```elm
map: (a -> b) -> a -> b
map fn value =
    fn value
```

## 1.0.0

-   [x] An automatic formatter with no options
-   [ ] A standard library
-   [ ] Support for [Coed](https://github.com/eeue56/coed)
-   [x] Testing support via [Bach](https://github.com/eeue56/bach)

Write a file with `_test` as an extension (e.g `List_test.derw`).

```elm
import Test exposing (equals)

testMath: boolean -> void
testMath a? =
    equals 1 1
```

Compile it, then run bach via `npx @eeue56/bach`

-   [ ] Type checking
-   [ ] Benchmarking support via [Mainc](https://github.com/eeue56/mainc)
-   [ ] Async support
-   [ ] Packaging
-   [x] Package init

```
derw --init
```

-   [x] Package testing

```
# inside a package directory
derw --test
```

# 2.0.0

-   [ ] Type checking with interop with TypeScript
-   [ ] Derw compiler is written in Derw

# Divergence from Elm

-   All top level consts or functions must have type definitions
-   Format strings ``
-   No need for module names in the module file itself. Use `exposing` instead

# Editor language support

Currently VSCode syntax highlighting is supported by this extension: https://github.com/eeue56/derw-syntax. It is not on the marketplace because Microsoft account creation was down when I tried.

Instead, you can do:

```
git clone https://github.com/eeue56/derw-syntax
cp -r derw-syntax ~/.vscode/extensions/derw-syntax-0.0.1
```

# Name

derw which means oak. Oak is one of the native trees in Wales, famous for it's long life, tall stature, and hard, good quality wood. An English speaker might pronounce it as "deh-ru".

---
_Source: https://npm.io/package/@eeue56/derw · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
