-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
471 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
unsafe-perm=true | ||
audit=false | ||
enable-pre-post-scripts=true | ||
fund=false | ||
package-lock=false | ||
prefer-dedupe=true | ||
prefer-offline=true | ||
save-prefix=~ | ||
save=false | ||
strict-peer-dependencies=false | ||
unsafe-perm=true | ||
loglevel=error | ||
shamefully-hoist=true | ||
resolution-mode=highest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"main": "../src/lightweight.js", | ||
"main": "index.js", | ||
"type": "module", | ||
"types": "index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict' | ||
|
||
const urlHttp = require('url-http/lightweight') | ||
const { flattie: flatten } = require('flattie') | ||
|
||
const factory = require('./factory') | ||
const { default: ky } = require('ky') | ||
|
||
class MicrolinkError extends Error { | ||
constructor (props) { | ||
super() | ||
this.name = 'MicrolinkError' | ||
Object.assign(this, props) | ||
this.description = this.message | ||
this.message = this.code | ||
? `${this.code}, ${this.description}` | ||
: this.description | ||
} | ||
} | ||
|
||
const got = async (url, opts) => { | ||
try { | ||
if (opts.retry > 0) opts.retry = opts.retry + 1 | ||
if (opts.timeout === undefined) opts.timeout = false | ||
const response = await ky(url, opts) | ||
const body = await response.json() | ||
const { headers, status: statusCode } = response | ||
return { url: response.url, body, headers, statusCode } | ||
} catch (err) { | ||
if (err.response) { | ||
const { response } = err | ||
err.response = { | ||
...response, | ||
headers: Array.from(response.headers.entries()).reduce( | ||
(acc, [key, value]) => { | ||
acc[key] = value | ||
return acc | ||
}, | ||
{} | ||
), | ||
statusCode: response.status, | ||
body: await response.text() | ||
} | ||
} | ||
throw err | ||
} | ||
} | ||
|
||
module.exports = factory({ | ||
MicrolinkError, | ||
urlHttp, | ||
got, | ||
flatten, | ||
VERSION: require('../package.json').version | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
import { createRequire } from 'module' | ||
import { $ } from 'execa' | ||
import test from 'ava' | ||
|
||
const require = createRequire(import.meta.url) | ||
const pkg = require('../package.json') | ||
|
||
const evalScript = code => $`node -e ${code}` | ||
|
||
test('cjs', async t => { | ||
// eslint-disable-next-line no-template-curly-in-string | ||
const code = "console.log(`mql v${require('@microlink/mql').version}`)" | ||
const { stdout } = await evalScript(code) | ||
t.is(stdout, `mql v${pkg.version}`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.