Skip to content

Commit

Permalink
feat: add types for packages (#677)
Browse files Browse the repository at this point in the history
* feat: add types for packages

Closes #676

* refactor(types): use declare
  • Loading branch information
Kikobeats authored Dec 18, 2023
1 parent 2eb11ef commit 8b8339c
Show file tree
Hide file tree
Showing 76 changed files with 306 additions and 35 deletions.
3 changes: 2 additions & 1 deletion packages/metascraper-amazon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Metascraper integration with Amazon",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-amazon",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
2 changes: 2 additions & 0 deletions packages/metascraper-amazon/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function rules(): import('metascraper').Rules;
export = rules;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const {
url
} = require('@metascraper/helpers')

const REGEX_AMAZON_URL = /https?:\/\/(.*amazon\..*\/.*|.*amzn\..*\/.*|.*a\.co\/.*)/i
const REGEX_AMAZON_URL =
/https?:\/\/(.*amazon\..*\/.*|.*amzn\..*\/.*|.*a\.co\/.*)/i

const test = memoizeOne(url => REGEX_AMAZON_URL.test(url))

Expand Down
3 changes: 2 additions & 1 deletion packages/metascraper-audio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Get audio property from HTML markup",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-audio",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
11 changes: 11 additions & 0 deletions packages/metascraper-audio/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type IframeAttributes = {
src: string
}

type Options = {
getIframe?: (url: string, htmlDom: import('cheerio').CheerioAPI, iframeAttributes: IframeAttributes) => string;
}

declare function rules(options?: Options): import('metascraper').Rules;
export = rules;

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ module.exports = ({ getIframe = _getIframe } = {}) => {
return {
audio: audioRules.concat(
async ({ htmlDom: $, url }) => {
const srcs = [...new $('iframe').map((_, element) => $(element).attr('src')).get().map(src => normalizeUrl(url, src))]
const srcs = [
...new $('iframe')
.map((_, element) => $(element).attr('src'))
.get()
.map(src => normalizeUrl(url, src))
]
if (srcs.length === 0) return
return pReflect(
Promise.any(
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-audio/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const test = require('ava')

const createMetascraper = (...args) =>
require('metascraper')([require('..')(...args)])
require('metascraper')([require('../src')(...args)])

test('og:audio', async t => {
const html =
Expand Down
3 changes: 2 additions & 1 deletion packages/metascraper-author/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Get author property from HTML markup",
"homepage": "https://metascraper.js.org",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
2 changes: 2 additions & 0 deletions packages/metascraper-author/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function rules(): import('metascraper').Rules;
export = rules;
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/metascraper-clearbit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Metascraper integration with Clearbit Logo API",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-clearbit",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
21 changes: 21 additions & 0 deletions packages/metascraper-clearbit/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
type Options = {
/**
* https://github.com/sindresorhus/got#options
*/
gotOpts?: import('got').Options,
/**
* https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions
*/
keyvOpts?: import('@keyvhq/core').Options,
/**
* https://dashboard.clearbit.com/docs#logo-api
*/
logoOpts?: {
size: number,
format: "png" | "jpg"
greyscale: false
}
}

declare function rules(options?: Options): import('metascraper').Rules;
export = rules;
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/metascraper-clearbit/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const test = require('ava')

const createMetascraper = (...args) =>
require('metascraper')([require('..')(...args)])
require('metascraper')([require('../src')(...args)])

test('provide `keyvOpts`', async t => {
const cache = new Map()
Expand Down
3 changes: 2 additions & 1 deletion packages/metascraper-date/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Get date property from HTML markup",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-date",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "scripts/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
15 changes: 15 additions & 0 deletions packages/metascraper-date/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type Options = {
/**
* Whether to add the date published and date modified to the result.
* @default true
*/
datePublished?: boolean,
/**
* Whether to add the date published and date modified to the result.
* @default true
*/
dateModified?: boolean
}

declare function rules(options?: Options = defaultOptions): import('metascraper').Rules;
export = rules;
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/metascraper-description/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Get description property from HTML markup",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-description",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
30 changes: 30 additions & 0 deletions packages/metascraper-description/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
type Options = {
/**
* The maximum length of the description.
* @default Number.MAX_SAFE_INTEGER
*/
truncateLength?: number,
/**
* The string to append if the description is truncated.
* @default '…'
*/
ellipsis?: string,
/**
* Whether to remove the byline from the description.
* @default false
*/
removeBy?: boolean,
/**
* Whether to remove the separator from the description.
* @default false
*/
removeSeparator?: boolean,
/**
* Whether to capitalize the description.
* @default false
*/
capitalize?: boolean
}

declare function rules(options?: Options): import('metascraper').Rules;
export = rules;
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/metascraper-feed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Get RSS/Atom feed URL from HTML markup",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-description",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
2 changes: 2 additions & 0 deletions packages/metascraper-feed/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function rules(): import('metascraper').Rules;
export = rules;
File renamed without changes.
1 change: 1 addition & 0 deletions packages/metascraper-iframe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-iframe",
"version": "5.40.0",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
9 changes: 9 additions & 0 deletions packages/metascraper-iframe/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type Options = {
/**
* https://github.com/sindresorhus/got#options
*/
gotOpts?: import('got').Options,
}

declare function rules(options?: Options): import('metascraper').Rules;
export = rules;
3 changes: 2 additions & 1 deletion packages/metascraper-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Get image property from HTML markup",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-image",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
2 changes: 2 additions & 0 deletions packages/metascraper-image/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function rules(): import('metascraper').Rules;
export = rules;
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/metascraper-instagram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Metascraper integration for Instagram",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-instagram",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
2 changes: 2 additions & 0 deletions packages/metascraper-instagram/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function rules(): import('metascraper').Rules;
export = rules;
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/metascraper-lang/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Get lang property from HTML markup",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-lang",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
2 changes: 2 additions & 0 deletions packages/metascraper-lang/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function rules(): import('metascraper').Rules;
export = rules;
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/metascraper-lang/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { readFile } = require('fs/promises')
const { resolve } = require('path')
const test = require('ava')

const metascraper = require('metascraper')([require('..')()])
const metascraper = require('metascraper')([require('../src')()])

test('html lang property', async t => {
const html = await readFile(resolve(__dirname, 'fixtures/html-lang.html'))
Expand Down
3 changes: 2 additions & 1 deletion packages/metascraper-logo-favicon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "metascraper logo favicon fallback",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-logo-favicon",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "types/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
36 changes: 36 additions & 0 deletions packages/metascraper-logo-favicon/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
type DOMNOdeAtributes = Record<string, any>

type Options = {
/**
* Enable favicon.ico detection
* @default true
*/
favicon?: boolean,
/**
* Enable favicon.ico using the root domain for subdomains
* @default true
*/
rootFavicon?: boolean | RegExp,
/**
* Enable retrieve logo from Google API.
* @default true
*/
google?: boolean,
/**
* https://github.com/sindresorhus/got#options
*/
gotOpts?: import('got').Options,
/**
* https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions
*/
keyvOpts?: import('@keyvhq/core').Options,
/**
* The function to pick the favicon from the list of favicons.
*/
pickFn?: (sizes: DOMNOdeAtributes[]) => DOMNOdeAtributes,
}

declare function rules(options?: Options): import('metascraper').Rules;
export = rules;


File renamed without changes.
3 changes: 2 additions & 1 deletion packages/metascraper-logo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Get logo property from HTML markup",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-logo",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
6 changes: 6 additions & 0 deletions packages/metascraper-logo/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type Options = {
filter?: (url: string) => boolean
}

declare function rules(options?: Options): import('metascraper').Rules;
export = rules;
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/metascraper-manifest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "Metascraper integration for detecting PWA Web app manifest",
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-manifest",
"version": "5.40.0",
"main": "index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down
13 changes: 13 additions & 0 deletions packages/metascraper-manifest/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type Options = {
/**
* https://github.com/sindresorhus/got#options
*/
gotOpts?: import('got').Options,
/**
* https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions
*/
keyvOpts?: import('@keyvhq/core').Options,
}

declare function rules(options?: Options): import('metascraper').Rules;
export = rules;
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ const memoize = require('@keyvhq/memoize')
const got = require('got')

const parseSize = str => {
const parse = Number(
chain(str)
.split('x')
.first()
.value()
)
const parse = Number(chain(str).split('x').first().value())
return Number.isNaN(parse) ? 0 : parse
}

Expand Down
3 changes: 2 additions & 1 deletion packages/metascraper-media-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-media-provider",
"version": "5.40.0",
"main": "src/index.js",
"types": "src/index.d.ts",
"author": {
"email": "[email protected]",
"name": "microlink.io",
Expand Down Expand Up @@ -32,7 +33,7 @@
"p-reflect": "~2.1.0",
"p-retry": "~4.6.1",
"p-timeout": "~4.1.0",
"youtube-dl-exec": "~2.4.12"
"youtube-dl-exec": "~2.5.2"
},
"devDependencies": {
"@kikobeats/time-span": "latest",
Expand Down
Loading

0 comments on commit 8b8339c

Please sign in to comment.