Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tbeseda/waylon

Node.js HTML string helpers
https://github.com/tbeseda/waylon

helpers html nodejs strings

Last synced: 5 days ago
JSON representation

Node.js HTML string helpers

Awesome Lists containing this project

README

        

โ˜ฃ๏ธ This is a prototype!



Don't go putting this into production.

I'm not super keen on the API yet. Breaking changes will be minors and everything else is a patch.

Until v1. Then I'll keep a CHANGELOG and stick to proper semver.






I'm a Ramblin' Man







Waylon ๐ŸŒต


HTML string helpers, particularly great in Node.js string template literals.

Lonesome, On'ry, and Mean

waylon on npmjs.org ยป



Entities:
Item
โ€ข
List
โ€ข
Collection

## Install

```
npm i waylon
```

## Usage

๐Ÿ“ **Some goals, thoughts, notes:**
- Class methods always return a string of HTML
- User never *has* to author a bracketed HTML tag
- `$` generally denotes "this thing is HTML"

### Item

When you've got a single object: `Item`

```js
import { Item } from "waylon";

const data = { first: "Kris", last: "Kristofferson", born: 1936 };

const kris = new Item(data);
```

```js
const $link = kris.link("https://en.wikipedia.org/wiki/Kris_Kristofferson", data.first);
```

> Kris

```js
const dataAttrs = kris.dataAttrs();
```

> data-first="Kris" data-last="Kristofferson" data-born="1936"

```js
const attrs = kris.attrs();
```

> first="Kris" last="Kristofferson" born="1936"

Suggestions? File an issue.

### List

Suggestions? File an issue.

### Collection

When you've got an array of objects: `Collection`

```js
import { Collection } from "waylon";

const data = [
{ first: "Waylon", last: "Jennings", born: 1937 },
{ first: "Willie", last: "Nelson", born: 1933 },
{ first: "Kris", last: "Kristofferson", born: 1936 },
{ first: "Johnny", last: "Cash", born: 1932 },
];

const highwaymen = new Collection(data);
```

๐ŸŽถ I Ain't Living Long Like This...

```js
const $list = highwaymen.list(["first", "last"]);
```


  • Waylon Jennings

  • Willie Nelson

  • Kris Kristofferson

  • Johnny Cash

```js
const $ul = highwaymen.ul("first");
```


  • Waylon

  • Willie

  • Kris

  • Johnny

```js
const $ol = highwaymen.ol("born");
```


  1. 1937

  2. 1933

  3. 1936

  4. 1932

```js
const $table = highwaymen.table();
```

firstlastbornWaylonJennings1937WillieNelson1933KrisKristofferson1936JohnnyCash1932

```js
const $listSeparated = highwaymen.list(["last", "first"], ", ");
```


  • Jennings, Waylon

  • Nelson, Willie

  • Kristofferson, Kris

  • Cash, Johnny

```js
const $listTemplated = highwaymen.list(
({ first, last, born }) => `${first} ${last}: ${born}`,
);
```


  • Waylon Jennings: 1937

  • Willie Nelson: 1933

  • Kris Kristofferson: 1936

  • Johnny Cash: 1932

## FAQ

Why "waylon"?

`waylon` is pretty scrappy. No dependencies, simple, and straight forward. Not necessarily revolutionary, but not going to conform to the mainstream ~~Nashville Sound~~ way of making HTML.

Also, I was squatting the name on npmjs.org because I'm a big fan of Waylon Jennings. But I don't want to be that guy and just hold a great name. So here we are!







...





It's just strings.

Plus, I've never been to Spain.