Skip to content

Commit

Permalink
build: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Feb 3, 2019
0 parents commit 8cf91a9
Show file tree
Hide file tree
Showing 18 changed files with 390 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .bumpedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
files:
- package.json
plugins:
prerelease:
Linting config files:
plugin: bumped-finepack
postrelease:
Generating CHANGELOG file:
plugin: bumped-changelog
Committing new version:
plugin: bumped-terminal
command: 'git add CHANGELOG.md package.json && git commit -m "Release $newVersion"'
Detecting problems before publish:
plugin: bumped-terminal
command: 'git-dirty && npm test'
Publishing tag to GitHub:
plugin: bumped-terminal
command: 'git tag $newVersion && git push && git push --tags'
Publishing to NPM:
plugin: bumped-terminal
command: npm publish
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
indent_brace_style = 1TBS
spaces_around_operators = true
quote_type = auto

[package.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
############################
# npm
############################
node_modules
npm-debug.log
.node_history
yarn.lock
package-lock.json

############################
# tmp, editor & OS files
############################
.tmp
*.swo
*.swp
*.swn
*.swm
.DS_Store
*#
*~
.idea
*sublime*
nbproject

############################
# Tests
############################
testApp
coverage
.nyc_output

############################
# Other
############################
.env
.envrc
4 changes: 4 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unsafe-perm=true
save-prefix=~
shrinkwrap=false
save=false
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "node"
- "lts/*"
after_success: npm run coverage
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright © 2019 microlink.io <hello@microlink.io> (microlink.io)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1 align="center">
<img src="https://microlink.io/banner_mql.png" alt="microlink logo">
</h1>

*WORK IN PROGRESS*

## License

**mql** © [microlink.io](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/mql/blob/master/LICENSE.md) License.<br>
Authored and maintained by microlink.io with help from [contributors](https://github.com/microlinkhq/mql/contributors).

> [microlink.io](https://microlink.io) · GitHub [microlink.io](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)
97 changes: 97 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"name": "mql",
"description": "Microlink Query Language",
"homepage": "https://documentup.com/microlinkhq/mql",
"version": "0.0.0",
"main": "src/node.js",
"author": {
"name": "microlink.io",
"email": "hello@microlink.io",
"url": "https://microlink.io"
},
"repository": {
"type": "git",
"url": "git+https://github.com/microlinkhq/mql.git"
},
"bugs": {
"url": "https://github.com/microlinkhq/mql/issues"
},
"keywords": [
"microlink"
],
"dependencies": {
"got": "~9.6.0",
"is-url-http": "~1.0.1",
"whoops": "~4.0.1"
},
"devDependencies": {
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"ava": "latest",
"conventional-github-releaser": "latest",
"coveralls": "latest",
"finepack": "latest",
"git-authors-cli": "latest",
"git-dirty": "latest",
"husky": "latest",
"lint-staged": "latest",
"npm-check-updates": "latest",
"nyc": "latest",
"prettier-standard": "latest",
"standard": "latest",
"standard-markdown": "latest",
"standard-version": "latest"
},
"engines": {
"node": ">= 8"
},
"scripts": {
"clean": "rm -rf node_modules",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint": "standard-markdown README.md && standard",
"postrelease": "npm run release:tags && npm run release:github && npm publish",
"precommit": "lint-staged",
"prerelease": "git-dirty && npm run update:check && npm test && git-authors-cli",
"pretest": "npm run lint",
"pretty": "prettier-standard index.js {core,test,bin,scripts}/**/*.js --single-quote --print-width 100",
"release": "git add package.json && standard-version -a",
"release:github": "conventional-github-releaser -p angular",
"release:tags": "git push --follow-tags origin master",
"test": "nyc ava",
"update": "ncu -a",
"update:check": "ncu -- --error-level 2"
},
"license": "MIT",
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"linters": {
"package.json": [
"finepack",
"git add"
],
"*.js": [
"prettier-standard",
"git add"
],
"*.md": [
"standard-markdown",
"git add"
]
}
},
"standard-version": {
"scripts": {
"prechangelog": "git-authors-cli"
}
}
}
48 changes: 48 additions & 0 deletions src/factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

const ENDPOINT = {
FREE: 'https://api.microlink.io',
PRO: 'https://pro.microlink.io'
}

module.exports = ({ whoops, isUrlHttp, stringify, got }) => {
const MicrolinkError = whoops('MicrolinkError')

const assertUrl = url => {
if (!isUrlHttp(url)) {
throw new MicrolinkError({
code: 'ENOVALIDURL',
message: `The \`url\` value ${
url ? `'${url}' ` : ''
}is not a valid HTTP URL.`.trim()
})
}
}

const apiUrl = (url, { key, ...opts } = {}) => {
const isPro = !!key
const endpoint = ENDPOINT[isPro ? 'PRO' : 'FREE']
const apiUrl = `${endpoint}?${stringify({ url: url, ...opts })}`
const headers = isPro ? { 'x-api-key': key } : {}
return [apiUrl, { headers }]
}

// TODO: Add `agent` support
// TODO: Add local `cache` support: https://www.npmjs.com/package/got#cache-1
// TODO: Add `batch` support https://www.npmjs.com/package/dataloader
const MQL = async (
targetUrl,
{ retry = 3, timeout = 25000, ...opts } = {}
) => {
assertUrl(targetUrl)
const [url, { headers }] = apiUrl(targetUrl, opts)
const response = await got(url, { retry, timeout, headers, json: true })
const { body } = response
return { ...body, response }
}

MQL.MicrolinkError = MicrolinkError
MQL.apiUrl = apiUrl

return MQL
}
6 changes: 6 additions & 0 deletions src/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = require('./factory')({
whoops: require('whoops'),
isUrlHttp: require('is-url-http'),
stringify: require('querystring').stringify,
got: require('got')
})
12 changes: 12 additions & 0 deletions test/api-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'

import test from 'ava'
import { apiUrl } from '..'

test('url without query params', t => {
t.snapshot(apiUrl('https://kikobeats.com'))
})

test('key', t => {
t.snapshot(apiUrl('https://kikobeats.com', { key: 'foobar' }))
})
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

import test from 'ava'
import MQL from '..'

test('simple url', async t => {
const { status, data, response } = await MQL('https://kikobeats.com')
t.snapshot(status)
t.snapshot(data)
t.snapshot(response.url)
})
29 changes: 29 additions & 0 deletions test/snapshots/api-url.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Snapshot report for `test/api-url.js`

The actual snapshot is saved in `api-url.js.snap`.

Generated by [AVA](https://ava.li).

## key

> Snapshot 1
[
'https://pro.microlink.io?url=https%3A%2F%2Fkikobeats.com',
{
headers: {
'x-api-key': 'foobar',
},
},
]

## url without query params

> Snapshot 1
[
'https://api.microlink.io?url=https%3A%2F%2Fkikobeats.com',
{
headers: {},
},
]
Binary file added test/snapshots/api-url.js.snap
Binary file not shown.
43 changes: 43 additions & 0 deletions test/snapshots/index.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Snapshot report for `test/index.js`

The actual snapshot is saved in `index.js.snap`.

Generated by [AVA](https://ava.li).

## simple url

> Snapshot 1
'success'

> Snapshot 2
{
author: 'kikobeats',
date: null,
description: 'A millennial doing stuff on internet that ships software every day and builds digital products.',
image: {
height: 500,
size: 30285,
size_pretty: '30.3 kB',
type: 'jpg',
url: 'https://kikobeats.com/images/avatar-glitch.jpg',
width: 500,
},
lang: 'en',
logo: {
height: 500,
size: 30285,
size_pretty: '30.3 kB',
type: 'jpg',
url: 'https://kikobeats.com/images/avatar-glitch.jpg',
width: 500,
},
publisher: 'Kikobeats',
title: 'Kikobeats',
url: 'https://kikobeats.com/',
}

> Snapshot 3
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com'
Binary file added test/snapshots/index.js.snap
Binary file not shown.
Loading

0 comments on commit 8cf91a9

Please sign in to comment.