Skip to content

Commit

Permalink
Reduce installation size (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Richie Bendall <richiebendall@gmail.com>
  • Loading branch information
yhdgms1 and Richienb authored Mar 17, 2022
1 parent efab3f8 commit 22cef52
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4,354 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Lockfiles

package-lock.json
yarn.lock

# Visual Studio Code

.vscode/*
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"use strict"

const { default: ow } = require("ow")

const formats = [/https:\/\/drive\.google\.com\/file\/d\/(?<id>.*?)\/(?:edit|view)\?usp=sharing/, /https:\/\/drive\.google\.com\/open\?id=(?<id>.*?)$/]

const alphanumeric = /^[a-zA-Z0-9\-_]+$/
const alphanumeric = /^[\w-]+$/

module.exports = (url, apiKey) => {
ow(url, ow.string.minLength(1))
ow(apiKey, ow.optional.string.minLength(1).matches(alphanumeric))
if (typeof url !== "string") throw new Error("Invalid URL provided.")
if (typeof apiKey === "string" && !alphanumeric.test(apiKey)) throw new Error("Invalid api key provided.")

url = url.trim()

Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"scripts": {
"lint": "xo",
"test": "yarn lint && ava"
"test": "xo && uvu"
},
"keywords": [
"google",
Expand All @@ -27,11 +27,8 @@
"save",
"link"
],
"dependencies": {
"ow": "^0.15.1"
},
"devDependencies": {
"ava": "^3.0.0",
"uvu": "^0.5.3",
"eslint-config-richienb": "^0.3.0",
"xo": "^0.25.3"
},
Expand Down
29 changes: 26 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
const test = require("ava")
const { test } = require("uvu")
const { is, throws } = require("uvu/assert")
const driveURL = require(".")

test("main", (t) => {
t.is(driveURL("https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=sharing"), "https://drive.google.com/uc?export=download&id=1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk")
test("main", () => {
is(
driveURL(
"https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=sharing",
),
"https://drive.google.com/uc?export=download&id=1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk",
)
is(
driveURL(
"https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=sharing",
"foo",
),
"https://www.googleapis.com/drive/v3/files/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk?alt=media&key=foo",
)
})

test("errors", () => {
throws(() => driveURL(null), ({ message }) => message === "Invalid URL provided.")
throws(() => driveURL(""), ({ message }) => message === "Invalid URL provided.")

throws(() => driveURL("url", ""), ({ message }) => message === "Invalid api key provided.")
throws(() => driveURL("url", "$$$"), ({ message }) => message === "Invalid api key provided.")
})

test.run()
Loading

0 comments on commit 22cef52

Please sign in to comment.