Skip to content

Commit 67840fc

Browse files
leey00nsumheap
andauthored
Fix function isBase64 (#117)
* fix function isBase64 * Remove is-base64 dependency --------- Co-authored-by: Michael Heap <[email protected]>
1 parent 6fab85e commit 67840fc

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

create-or-update-files.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
const isBase64 = require("is-base64");
1+
function isBase64(str) {
2+
var notBase64 = /[^A-Z0-9+\/=]/i;
3+
const isString = (typeof str === 'string' || str instanceof String);
4+
5+
if (!isString) {
6+
let invalidType;
7+
if (str === null) {
8+
invalidType = 'null';
9+
} else {
10+
invalidType = typeof str;
11+
if (invalidType === 'object' && str.constructor && str.constructor.hasOwnProperty('name')) {
12+
invalidType = str.constructor.name;
13+
} else {
14+
invalidType = `a ${invalidType}`;
15+
}
16+
}
17+
throw new TypeError(`Expected string but received ${invalidType}.`);
18+
}
19+
20+
const len = str.length;
21+
if (!len || len % 4 !== 0 || notBase64.test(str)) {
22+
return false;
23+
}
24+
const firstPaddingChar = str.indexOf('=');
25+
return firstPaddingChar === -1 ||
26+
firstPaddingChar === len - 1 ||
27+
(firstPaddingChar === len - 2 && str[len - 1] === '=');
28+
}
29+
230
module.exports = function (octokit, opts) {
331
return new Promise(async (resolve, reject) => {
432
// Up front validation

package-lock.json

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"nock": "^13.3.3"
2626
},
2727
"dependencies": {
28-
"is-base64": "^1.1.0"
2928
},
3029
"peerDependencies": {
3130
"@octokit/rest": ">=20.0.1"

0 commit comments

Comments
 (0)