Markdown post-compilation utilities so tiny, they must be fleas!
npm install @hackdoor/flea| service | status |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| Codecov |  |
| GitHub CI | !Node.js CI |
An immutable, purely functional, type-safe micro-library that exposes some nice utilities for markdown-compilation post processing on both client and server.
You can install flea from npm:
``bash`
npm i -s @hackdoor/flea
`bash`
yarn add @hackdoor/flea
The list of flea exported functions:
- anchors
- href
- readingTime
`typescript
import { anchors } from "@hackdoor/anchors";
const replaceAnchors = anchors();
const myHTMLInput =
Lorem ipsum dolor sit amet, consectetur adipiscing elit...
Curabitur pretium tincidunt lacus. Nulla gravida orci a...
Ut ullamcorper, ligula eu tempor congue, eros est euism...
;const result = replaceAnchors(myHTMLInput);
//
//
// #
// Lorem Ipsum Dolor Sit Amet
//
// Lorem ipsum dolor sit amet, consectetur adipiscing elit...
//
// #
// Consectetur Adipiscing Elit
//
// Curabitur pretium tincidunt lacus. Nulla gravida orci a...
//
// #
// Sed Do Eiusmod Tempor Incididunt Ut
//
// Ut ullamcorper, ligula eu tempor congue, eros est euism...
//
`href
`typescript
import { href } from "@hackdoor/flea";const replaceHrefs = href({ baseURL: "https://www.google.com" });
const myHTMLInput =
;const result = replaceHrefs(myHTMLInput);
//
`Options
| name | required | type | default value | description |
| --------- | -------- | --------- | ------------- | --------------------------------------------------------------------------------------------------------------------- |
| baseURL |
false | string | "" | the url to prevent for adding target="_blank" |
| internals | false | boolean | false | set to true if you want to apply href to internals links too (those starting with /, for instance: /articles) |
readingTime
`typescript
import { readingTime } from "@hackdoor/flea";
const myHTMLInput = ;const readingInfo = readingTime({ text: myHTMLInput });
// {
// duration: 0.0036363636363636364,
// imageTime: 0,
// otherLanguageTime: 0,
// otherLanguageTimeCharacters: 0,
// roundedDuration: 1,
// totalImages: 0,
// totalWords: 1,
// wordTime: 0.0036363636363636364
// }
`Options
| name | required | type | default value | description |
| --------------------- | -------- | ---------- | -------------------- | -------------------------------------------------- |
| text |
true | string | "" | the text for calculate the reading time |
| customWordTime | false | number | 275 | number of words read per minute |
| customImageTime | false | number | 12 | maximum of seconds spent looking at an image |
| chineseKoreanReadTime | false | number | 500 | number of chinese and korean words read per minute |
| imageTags | false | string[] | [ 'img', 'Image' ]` | list of tags to identify images |