2.1.1 • Published 3 months ago

@paulrobertlloyd/mf2tojf2 v2.1.1

Weekly downloads
32
License
MIT
Repository
github
Last release
3 months ago

MF2 to JF2

Build status

Convert MF2 to JF2.

JF2 is a simpler JSON serialization of microformats2 intended to be easier to consume than the standard microformats JSON representation.

Requirements

Usage

Simple (synchronous)

import { mf2tojf2 } from "mf2tojf2";

const mf2 = {
  items: [
    {
      type: ["h-card"],
      properties: {
        name: ["Paul Robert Lloyd"],
        url: ["https://paulrobertlloyd.com"],
      },
    },
  ],
};

const jf2 = mf2tojf2(mf2);

console.log(jf2);

Returns:

{
  type: "card",
  name: "Paul Robert Lloyd",
  url: "https://paulrobertlloyd.com"
}

With references (asynchronous)

JF2 can include a references property to exclude any non-authoritative data from the defined object.

import { mf2tojf2referenced } from "mf2tojf2";

const mf2 = {
  items: [
    {
      type: ["h-entry"],
      properties: {
        name: ["What my friend ate for lunch yesterday"],
        published: ["2019-02-12T10:00:00.000+00:00"],
        url: ["https://my-website.example/bookmarks/lunch"],
        "bookmark-of": ["https://their-website.example/notes/lunch"],
        "mp-syndicate-to": "https://example.social/@username",
      },
    },
  ],
};

const jf2WithReferences = await mf2tojf2referenced(mf2);

console.log(jf2WithReferences);

Returns:

{
  type: "entry",
  name: "What my friend ate for lunch yesterday",
  published: "2019-02-12T10:00:00.000+00:00",
  url: "https://my-website.example/bookmarks/lunch",
  "bookmark-of": "https://their-website.example/notes/lunch",
  "mp-syndicate-to": "https://example.social/@username",
  references: {
    "https://their-website.example/notes/lunch": {
      type: "entry",
      name: "What I ate for lunch",
      published: "2019-01-12T15:55:00.000+00:00",
      url: "https://their-website.example/notes/lunch",
      content: {
        text: "I ate a cheese sandwich, which was nice.",
        html: "<p>I ate a cheese sandwich, which was nice.</p>"
      },
      category: ["Food", "Lunch", "Sandwiches"]
    }
  }
}

!NOTE\ Values for url, and any property prefixed with mp-, are excluded from referencing.

Testing

npm test

Releasing a new version

npm run release

Credits

Based on mf2tojf2.py.

2.1.1

3 months ago

2.1.0

3 months ago

1.1.0

7 months ago

2.0.0

6 months ago

1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

4 years ago

0.2.1

4 years ago