Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extend dependency, becoming a zero-dependency package #9821

Merged
merged 5 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const fs = require('fs');
const path = require('path');
const extend = require('extend');

function load() {
// Recursively load one or more directories passed as arguments.
Expand All @@ -23,7 +22,7 @@ function load() {

// The JSON data is independent of the actual file
// hierarchy, so it is essential to extend "deeply".
result = extend(true, result, extra);
extend(result, extra);
}

for (dir of arguments) {
Expand All @@ -34,6 +33,26 @@ function load() {
return result;
}

function isPlainObject(v) {
return typeof v === 'object' && v !== null && !Array.isArray(v);
}

function extend(target, source) {
if (!isPlainObject(target) || !isPlainObject(source)) {
throw new Error('Both target and source must be plain objects');
}

// iterate over own enumerable properties
for (const [key, value] of Object.entries(source)) {
// recursively extend if target has the same key, otherwise just assign
if (Object.prototype.hasOwnProperty.call(target, key)) {
extend(target[key], value);
} else {
target[key] = value;
}
}
}

module.exports = load(
'api',
'browsers',
Expand Down
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"description": "Browser compatibility data provided by MDN Web Docs",
"main": "index.js",
"types": "index.d.ts",
"dependencies": {
"extend": "3.0.2"
},
"engines": {
"node": ">=10.0.0"
},
Expand Down