xast-util-feed
Advanced tools
Comparing version 1.2.1 to 1.2.2
/** | ||
* Build an Atom feed. | ||
* | ||
* Same API as `rss` otherwise. | ||
@@ -7,3 +8,3 @@ * | ||
* Data on the feed (the group of items). | ||
* @param {Array<Entry>} [data] | ||
* @param {Array<Entry> | null | undefined} [data] | ||
* List of entries. | ||
@@ -15,3 +16,3 @@ * @returns {Root} | ||
channel: Channel, | ||
data?: import('./types.js').Entry[] | undefined | ||
data?: Array<Entry> | null | undefined | ||
): Root | ||
@@ -18,0 +19,0 @@ export type Element = import('xast').Element |
@@ -17,2 +17,3 @@ /** | ||
* Build an Atom feed. | ||
* | ||
* Same API as `rss` otherwise. | ||
@@ -22,3 +23,3 @@ * | ||
* Data on the feed (the group of items). | ||
* @param {Array<Entry>} [data] | ||
* @param {Array<Entry> | null | undefined} [data] | ||
* List of entries. | ||
@@ -25,0 +26,0 @@ * @returns {Root} |
/** | ||
* Build an RSS feed. | ||
* | ||
* Same API as `atom` otherwise. | ||
@@ -7,3 +8,3 @@ * | ||
* Data on the feed (the group of items). | ||
* @param {Array<Entry>} [data] | ||
* @param {Array<Entry> | null | undefined} [data] | ||
* List of entries. | ||
@@ -15,3 +16,3 @@ * @returns {Root} | ||
channel: Channel, | ||
data?: import('./types.js').Entry[] | undefined | ||
data?: Array<Entry> | null | undefined | ||
): Root | ||
@@ -18,0 +19,0 @@ export type Element = import('xast').Element |
@@ -16,2 +16,3 @@ /** | ||
* Build an RSS feed. | ||
* | ||
* Same API as `atom` otherwise. | ||
@@ -21,3 +22,3 @@ * | ||
* Data on the feed (the group of items). | ||
* @param {Array<Entry>} [data] | ||
* @param {Array<Entry> | null | undefined} [data] | ||
* List of entries. | ||
@@ -31,4 +32,4 @@ * @returns {Root} | ||
const meta = channel || {title: null, url: null} | ||
/** @type {boolean|undefined} */ | ||
let atom | ||
/** @type {boolean} */ | ||
let atom = false | ||
@@ -35,0 +36,0 @@ if (meta.title === undefined || meta.title === null) { |
/** | ||
* An author object | ||
* Author object | ||
*/ | ||
export type Author = { | ||
/** | ||
* Example: `'Acme, Inc.'` or `'Jane Doe'` | ||
* Name (example: `'Acme, Inc.'` or `'Jane Doe'`). | ||
*/ | ||
name: string | ||
/** | ||
* Example: `john@example.org` | ||
* Email address (example: `john@example.org`). | ||
*/ | ||
email?: string | undefined | ||
email?: string | null | undefined | ||
/** | ||
* Example: `'https://example.org/john'`. | ||
* URL to author (example: `'https://example.org/john'`). | ||
* | ||
* `url` is used in `atom`, not in `rss`. | ||
*/ | ||
url?: string | undefined | ||
url?: string | null | undefined | ||
} | ||
/** | ||
* Media | ||
* Media. | ||
*/ | ||
@@ -53,28 +54,32 @@ export type Enclosure = { | ||
* `'https://www.adweek.com/feed/'`). | ||
* | ||
* Make sure to pass different ones to `rss` and `atom`! | ||
* | ||
* You *should* define this. | ||
*/ | ||
feedUrl?: string | undefined | ||
feedUrl?: string | null | undefined | ||
/** | ||
* Short description of the channel (example: `Album Reviews`). | ||
* | ||
* You *should* define this. | ||
*/ | ||
description?: string | undefined | ||
description?: string | null | undefined | ||
/** | ||
* BCP 47 language tag representing the language of the whole channel (example: | ||
* `'fr-BE'`). | ||
* | ||
* You *should* define this. | ||
*/ | ||
lang?: string | undefined | ||
lang?: string | null | undefined | ||
/** | ||
* Optional author of the whole channel. | ||
* | ||
* Either `string`, in which case it’s as passing `{name: string}`. | ||
* Or an author object. | ||
*/ | ||
author?: string | Author | undefined | ||
author?: string | Author | null | undefined | ||
/** | ||
* Categories of the channel (example: | ||
* `['JavaScript', 'React']`). | ||
* Categories of the channel (example: `['JavaScript', 'React']`). | ||
*/ | ||
tags?: Array<string> | undefined | ||
tags?: Array<string> | null | undefined | ||
} | ||
@@ -87,26 +92,33 @@ /** | ||
* Title of the item (example: `'Playboi Carti: Whole Lotta Red'`). | ||
* | ||
* Either `title`, `description`, or `descriptionHtml` must be set. | ||
*/ | ||
title?: string | undefined | ||
title?: string | null | undefined | ||
/** | ||
* Either the whole post or an excerpt of it (example: `'Lorem'`). | ||
* | ||
* Should be plain text. | ||
* `descriptionHtml` is preferred over plain text `description`. | ||
* | ||
* Either `title`, `description`, or `descriptionHtml` must be set. | ||
*/ | ||
description?: string | undefined | ||
description?: string | null | undefined | ||
/** | ||
* Either the whole post or an excerpt of it (example: `'<p>Lorem</p>'`). | ||
* | ||
* Should be serialized HTML. | ||
* `descriptionHtml` is preferred over plain text `description`. | ||
* | ||
* Either `title`, `description`, or `descriptionHtml` must be set. | ||
*/ | ||
descriptionHtml?: string | undefined | ||
descriptionHtml?: string | null | undefined | ||
/** | ||
* Entry version of `channel.author`. | ||
* | ||
* You *should* define this. | ||
* | ||
* For `atom`, it is required to either set `channel.author` or set `author` | ||
* on all entries. | ||
*/ | ||
author?: string | Author | undefined | ||
author?: string | Author | null | undefined | ||
/** | ||
@@ -116,3 +128,3 @@ * Full URL of this entry on the *site* (example: | ||
*/ | ||
url?: string | undefined | ||
url?: string | null | undefined | ||
/** | ||
@@ -122,3 +134,3 @@ * When the entry was first published (`Date` or value for `new Date(x)`, | ||
*/ | ||
published?: Date | number | string | undefined | ||
published?: Date | number | string | null | undefined | ||
/** | ||
@@ -128,3 +140,3 @@ * When the entry was last modified (`Date` or value for `new Date(x)`, | ||
*/ | ||
modified?: Date | number | string | undefined | ||
modified?: Date | number | string | null | undefined | ||
/** | ||
@@ -134,7 +146,7 @@ * Categories of the entry (`Array<string>?`, example: | ||
*/ | ||
tags?: Array<string> | undefined | ||
tags?: Array<string> | null | undefined | ||
/** | ||
* Attached media. | ||
*/ | ||
enclosure?: Enclosure | undefined | ||
enclosure?: Enclosure | null | undefined | ||
} |
/** | ||
* @typedef Author | ||
* An author object | ||
* Author object | ||
* @property {string} name | ||
* Example: `'Acme, Inc.'` or `'Jane Doe'` | ||
* @property {string|undefined} [email] | ||
* Example: `john@example.org` | ||
* @property {string|undefined} [url] | ||
* Example: `'https://example.org/john'`. | ||
* Name (example: `'Acme, Inc.'` or `'Jane Doe'`). | ||
* @property {string | null | undefined} [email] | ||
* Email address (example: `john@example.org`). | ||
* @property {string | null | undefined} [url] | ||
* URL to author (example: `'https://example.org/john'`). | ||
* | ||
* `url` is used in `atom`, not in `rss`. | ||
* | ||
* @typedef Enclosure | ||
* Media | ||
* Media. | ||
* @property {string} url | ||
@@ -29,53 +30,66 @@ * Full URL to the resource (example: | ||
* `'https://www.theguardian.com/world/zimbabwe'`). | ||
* @property {string|undefined} [feedUrl] | ||
* @property {string | null | undefined} [feedUrl] | ||
* Full URL to this channel (example: | ||
* `'https://www.adweek.com/feed/'`). | ||
* | ||
* Make sure to pass different ones to `rss` and `atom`! | ||
* | ||
* You *should* define this. | ||
* @property {string|undefined} [description] | ||
* @property {string | null | undefined} [description] | ||
* Short description of the channel (example: `Album Reviews`). | ||
* | ||
* You *should* define this. | ||
* @property {string|undefined} [lang] | ||
* @property {string | null | undefined} [lang] | ||
* BCP 47 language tag representing the language of the whole channel (example: | ||
* `'fr-BE'`). | ||
* | ||
* You *should* define this. | ||
* @property {string|Author|undefined} [author] Optional author of the whole channel. | ||
* @property {string | Author | null | undefined} [author] | ||
* Optional author of the whole channel. | ||
* | ||
* Either `string`, in which case it’s as passing `{name: string}`. | ||
* Or an author object. | ||
* @property {Array<string>|undefined} [tags] Categories of the channel (example: | ||
* `['JavaScript', 'React']`). | ||
* @property {Array<string> | null | undefined} [tags] | ||
* Categories of the channel (example: `['JavaScript', 'React']`). | ||
* | ||
* @typedef Entry | ||
* Data on a single item. | ||
* @property {string|undefined} [title] | ||
* @property {string | null | undefined} [title] | ||
* Title of the item (example: `'Playboi Carti: Whole Lotta Red'`). | ||
* | ||
* Either `title`, `description`, or `descriptionHtml` must be set. | ||
* @property {string|undefined} [description] | ||
* @property {string | null | undefined} [description] | ||
* Either the whole post or an excerpt of it (example: `'Lorem'`). | ||
* | ||
* Should be plain text. | ||
* `descriptionHtml` is preferred over plain text `description`. | ||
* | ||
* Either `title`, `description`, or `descriptionHtml` must be set. | ||
* @property {string|undefined} [descriptionHtml] | ||
* @property {string | null | undefined} [descriptionHtml] | ||
* Either the whole post or an excerpt of it (example: `'<p>Lorem</p>'`). | ||
* | ||
* Should be serialized HTML. | ||
* `descriptionHtml` is preferred over plain text `description`. | ||
* | ||
* Either `title`, `description`, or `descriptionHtml` must be set. | ||
* @property {string|Author|undefined} [author] | ||
* @property {string | Author | null | undefined} [author] | ||
* Entry version of `channel.author`. | ||
* | ||
* You *should* define this. | ||
* | ||
* For `atom`, it is required to either set `channel.author` or set `author` | ||
* on all entries. | ||
* @property {string|undefined} [url] | ||
* @property {string | null | undefined} [url] | ||
* Full URL of this entry on the *site* (example: | ||
* `'https://pitchfork.com/reviews/albums/roberta-flack-first-take'`). | ||
* @property {Date|number|string|undefined} [published] | ||
* @property {Date | number | string | null | undefined} [published] | ||
* When the entry was first published (`Date` or value for `new Date(x)`, | ||
* optional). | ||
* @property {Date|number|string|undefined} [modified] | ||
* @property {Date | number | string | null | undefined} [modified] | ||
* When the entry was last modified (`Date` or value for `new Date(x)`, | ||
* optional). | ||
* @property {Array<string>|undefined} [tags] | ||
* @property {Array<string> | null | undefined} [tags] | ||
* Categories of the entry (`Array<string>?`, example: | ||
* `['laravel', 'debugging']`). | ||
* @property {Enclosure|undefined} [enclosure] | ||
* @property {Enclosure | null | undefined} [enclosure] | ||
* Attached media. | ||
@@ -82,0 +96,0 @@ */ |
@@ -5,11 +5,19 @@ /** | ||
/** | ||
* @param {Author|string} value | ||
* Create an author object. | ||
* | ||
* @param {Author | string} value | ||
* Author or string. | ||
* @returns {Author} | ||
* Valid author. | ||
*/ | ||
export function toAuthor(value: Author | string): Author | ||
/** | ||
* @param {Date|string|number} value | ||
* Create a date object. | ||
* | ||
* @param {Date | string | number} value | ||
* Serialized date, numeric date, actual date. | ||
* @returns {Date} | ||
* Valid date. | ||
*/ | ||
export function toDate(value: Date | string | number): Date | ||
export type Author = import('./types.js').Author |
@@ -6,4 +6,8 @@ /** | ||
/** | ||
* @param {Author|string} value | ||
* Create an author object. | ||
* | ||
* @param {Author | string} value | ||
* Author or string. | ||
* @returns {Author} | ||
* Valid author. | ||
*/ | ||
@@ -23,4 +27,8 @@ export function toAuthor(value) { | ||
/** | ||
* @param {Date|string|number} value | ||
* Create a date object. | ||
* | ||
* @param {Date | string | number} value | ||
* Serialized date, numeric date, actual date. | ||
* @returns {Date} | ||
* Valid date. | ||
*/ | ||
@@ -27,0 +35,0 @@ export function toDate(value) { |
{ | ||
"name": "xast-util-feed", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "xast utility to build feeds (rss, atom)", | ||
@@ -44,3 +44,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/tape": "^4.0.0", | ||
"@types/node": "^18.0.0", | ||
"c8": "^7.0.0", | ||
@@ -50,15 +50,13 @@ "prettier": "^2.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xast-util-to-xml": "^3.0.0", | ||
"xo": "^0.52.0" | ||
"xo": "^0.53.0" | ||
}, | ||
"scripts": { | ||
"prepack": "npm run build && npm run format", | ||
"build": "rimraf \"{lib/**,}*.d.ts\" && tsc && type-coverage", | ||
"build": "tsc --build --clean && tsc --build && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
@@ -65,0 +63,0 @@ }, |
176
readme.md
@@ -11,3 +11,3 @@ # xast-util-feed | ||
[xast][] utility to build (web) feeds ([RSS][], [Atom][]). | ||
[xast][] utility to build (web) feeds ([RSS][rss-spec], [Atom][atom-spec]). | ||
@@ -21,5 +21,7 @@ ## Contents | ||
* [API](#api) | ||
* [`atom(channel, data)`](#atomchannel-data) | ||
* [`rss(channel, data)`](#rsschannel-data) | ||
* [`atom(channel, data)`](#atomchannel-data) | ||
* [`Channel`](#channel-1) | ||
* [`Author`](#author) | ||
* [`Channel`](#channel) | ||
* [`Enclosure`](#enclosure) | ||
* [`Entry`](#entry) | ||
@@ -57,3 +59,3 @@ * [Types](#types) | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]: | ||
In Node.js (version 14.14+ and 16.0+), install with [npm][]: | ||
@@ -171,36 +173,67 @@ ```sh | ||
This package exports the identifiers `atom` and `rss`. | ||
This package exports the identifiers [`atom`][atom] and [`rss`][rss]. | ||
There is no default export. | ||
### `rss(channel, data)` | ||
### `atom(channel, data)` | ||
Build an RSS feed. | ||
Build an [Atom][atom-spec] feed. | ||
###### `channel` | ||
###### Parameters | ||
See [`Channel`][channel]. | ||
* `channel` ([`Channel`][channel]) | ||
— data on the feed (the group of items) | ||
* `data` ([`Array<Entry>`][entry], optional) | ||
— list of entries | ||
###### `data` | ||
###### Returns | ||
List of [`Entry`][entry] objects. | ||
Atom feed ([`Root`][root]). | ||
### `rss(channel, data)` | ||
Build an [RSS][rss-spec] feed. | ||
###### Parameters | ||
* `channel` ([`Channel`][channel]) | ||
— data on the feed (the group of items) | ||
* `data` ([`Array<Entry>`][entry], optional) | ||
— list of entries | ||
###### Returns | ||
[xast][] root ([`Root`][root]). | ||
RSS feed ([`Root`][root]). | ||
### `atom(channel, data)` | ||
### `Author` | ||
Build an Atom feed. | ||
Same API as `rss` otherwise. | ||
Author object (TypeScript type). | ||
##### Fields | ||
###### `name` | ||
Name (`string`, **required**, example: `'Acme, Inc.'` or `'Jane Doe'`). | ||
###### `email` | ||
Email address (`string`, optional, ,example: `john@example.org`) | ||
###### `url` | ||
URL to author (`string`, optional, example: `'https://example.org/john'`). | ||
`url` is used in `atom`, not in `rss`. | ||
### `Channel` | ||
Data on the feed (the group of items). | ||
Data on the feed (the group of items) (TypeScript type). | ||
###### `channel.title` | ||
##### Fields | ||
###### `title` | ||
Title of the channel (`string`, **required**, example: `Zimbabwe | The | ||
Guardian`). | ||
###### `channel.url` | ||
###### `url` | ||
@@ -210,67 +243,94 @@ Full URL to the *site* (`string`, **required**, example: | ||
###### `channel.feedUrl` | ||
###### `feedUrl` | ||
Full URL to this channel (`string?`, example: `'https://www.adweek.com/feed/'`). | ||
Make sure to pass different ones to `rss` and `atom` when you build both! | ||
You *should* define this. | ||
###### `channel.description` | ||
###### `description` | ||
Short description of the channel (`string?`, example: `Album Reviews`). | ||
You *should* define this. | ||
###### `channel.lang` | ||
###### `lang` | ||
[BCP 47][bcp47] language tag representing the language of the whole channel | ||
(`string?`, example: `'fr-BE'`). | ||
You *should* define this. | ||
###### `channel.author` | ||
###### `author` | ||
Optional author of the whole channel. | ||
Optional author of the whole channel (`string` or [`Author`][author]). | ||
Either `string`, in which case it’s as passing `{name: string}`. | ||
Or an object with the following fields: | ||
Or an author object. | ||
* `name` (`string`, example: `'Acme, Inc.'` or `'Jane Doe'`) | ||
* `email` (`string?`, example: `john@example.org`) | ||
* `url` (`string?`, example: `'https://example.org/john'`) | ||
###### `tags` | ||
`url` is used in `atom`, not in `rss`. | ||
###### `channel.tags` | ||
Categories of the channel (`Array<string>?`, example: `['JavaScript', | ||
'React']`). | ||
### `Enclosure` | ||
Media (TypeScript type). | ||
##### Fields | ||
###### `url` | ||
Full URL to the resource (`string`, **required**, example: | ||
`'http://dallas.example.com/joebob_050689.mp3'`). | ||
###### `size` | ||
Resource size in bytes (`number`, **required**, example: `24986239`). | ||
###### `type` | ||
Mime type of the resource (`string`, **required**, example: `'audio/mpeg'`). | ||
### `Entry` | ||
Data on a single item. | ||
Data on a single item (TypeScript type). | ||
###### `entry.title` | ||
##### Fields | ||
###### `title` | ||
Title of the item (`string?`, example: `'Playboi Carti: Whole Lotta Red'`). | ||
Either `title`, `description`, or `descriptionHtml` must be set. | ||
###### `entry.description` | ||
###### `description` | ||
Either the whole post or an excerpt of it (`string?`, example: `'Lorem'`). | ||
Should be plain text. | ||
`descriptionHtml` is preferred over plain text `description`. | ||
Either `title`, `description`, or `descriptionHtml` must be set. | ||
###### `entry.descriptionHtml` | ||
###### `descriptionHtml` | ||
Either the whole post or an excerpt of it (`string?`, example: `'<p>Lorem</p>'`). | ||
Should be serialized HTML. | ||
`descriptionHtml` is preferred over plain text `description`. | ||
Either `title`, `description`, or `descriptionHtml` must be set. | ||
###### `entry.author` | ||
###### `author` | ||
Entry version of [`channel.author`][channel-author]. | ||
Entry version of `channel.author`. | ||
You *should* define this. | ||
For `atom`, it is required to either set `channel.author` or set `author` on all | ||
entries. | ||
###### `entry.url` | ||
###### `url` | ||
@@ -280,3 +340,3 @@ Full URL of this entry on the *site* (`string?`, example: | ||
###### `entry.published` | ||
###### `published` | ||
@@ -286,7 +346,7 @@ When the entry was first published (`Date` or value for `new Date(x)`, | ||
###### `entry.modified` | ||
###### `modified` | ||
When the entry was last modified (`Date` or value for `new Date(x)`, optional). | ||
###### `entry.tags` | ||
###### `tags` | ||
@@ -296,17 +356,11 @@ Categories of the entry (`Array<string>?`, example: `['laravel', | ||
###### `entry.enclosure` | ||
###### `enclosure` | ||
An enclosure, such as an image or audio, is an object with the following fields: | ||
Attached media ([`Enclosure?`][enclosure]). | ||
* `url` (`string`, example: `'http://dallas.example.com/joebob_050689.mp3'`) | ||
— full URL to the resource | ||
* `size` (`number`, example: `24986239`) | ||
— resource size in bytes | ||
* `type` (`string`, example: `'audio/mpeg'`) | ||
— mime type of the resource | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
It exports the additional types `Author`, `Enclosure`, `Channel`, and `Entry`. | ||
It exports the additional types [`Author`][author], [`Channel`][channel], | ||
[`Enclosure`][enclosure], and [`Entry`][entry]. | ||
@@ -317,3 +371,3 @@ ## Compatibility | ||
versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. | ||
As of now, that is Node.js 14.14+ and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
@@ -346,3 +400,3 @@ | ||
[MIT][license] © [Titus Wormer][author] | ||
[MIT][license] © [Titus Wormer][wooorm] | ||
@@ -387,3 +441,3 @@ <!-- Definitions --> | ||
[author]: https://wooorm.com | ||
[wooorm]: https://wooorm.com | ||
@@ -402,12 +456,18 @@ [health]: https://github.com/syntax-tree/.github | ||
[rss]: https://www.rssboard.org/rss-specification | ||
[rss-spec]: https://www.rssboard.org/rss-specification | ||
[atom]: https://tools.ietf.org/html/rfc4287 | ||
[atom-spec]: https://tools.ietf.org/html/rfc4287 | ||
[bcp47]: https://github.com/wooorm/bcp-47 | ||
[atom]: #atomchannel-data | ||
[rss]: #rsschannel-data | ||
[author]: #author | ||
[channel]: #channel | ||
[enclosure]: #enclosure | ||
[entry]: #entry | ||
[channel-author]: #channelauthor |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36169
9
689
462