Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pvinis/arrow-magic
https://github.com/pvinis/arrow-magic
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pvinis/arrow-magic
- Owner: pvinis
- Created: 2021-12-03T15:55:54.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-23T06:01:06.000Z (11 months ago)
- Last Synced: 2024-04-24T18:54:18.193Z (9 months ago)
- Language: TypeScript
- Size: 121 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# arrow-magic
A great way to write simple arrow functions faster.
[![npm version](https://badge.fury.io/js/arrow-magic.svg)](https://badge.fury.io/js/arrow-magic)
## Why arrow-magic?
Have you ever written code similar to the one below?
```ts
const aThing = anotherThing.map(thing => thing.name)
```I'm sure you have.
How about something like this?
```ts
const aThing = anotherThing.map(x => x.name)
```Probably also yes, because we are programmers, and we want to be efficient, so we name `thing` to just `x` because it's just used in that one place and it's pretty obvious what we want to do with it.
Let me show you an even more efficient way to do it, that gets rid of the `x` too!
```ts
const aThing = anotherThing.map($("name"))
```Or maybe even like this.
```ts
const aThing = anotherThing.map($`name`)
```Ain't that cool? I love it.
## Installation
```sh
npm install arrow-magic
yarn add arrow-magic
```## Usage
Pretty simple.
```ts
import { $ } from "arrow-magic"const aThing = anotherThing.map($("name"))
```## Why is it named `$`?
Well, why not?
Ruby uses `&`, and that seems fine. I like `$`, and I also export it as `magic` and as `prop` in case you want something more.. english than `$`.
If you like some other symbol/name, feel free to make a PR!
## Is it any good?
[Yes.](https://github.com/glenjamin/node-fib#is-it-any-good)
## Do I lose anything by using this?
Not if you use the `$("name")` syntax. It even works with typescript and typechecking!
The `` $`name` `` syntax unfortunately loses typechecking. Maybe there is a way to keep it, but I couldn't find it. Please make a PR if you can make this happen!