Skip to content

Commit

Permalink
feat: Add deprecation notice for passing just an ID in. (#98)
Browse files Browse the repository at this point in the history
* feat: Add deprecation notice for passing just an ID in.

fixes #97
  • Loading branch information
lholmquist committed Jul 7, 2020
1 parent 5ebc89b commit 87dba0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/swapi-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const request = require('request');
const util = require('./util');
const { deprecate, capitaliseFirstLetter } = require('./util');

const BASE_URL = 'https://swapi.dev/api/';

Expand Down Expand Up @@ -35,7 +35,7 @@ function sendRequest (options) {

Object.keys(jsonBody).forEach(value => {
if (typeof jsonBody[value] !== 'function') {
jsonBody['get' + util.capitaliseFirstLetter(value)] = (() => {
jsonBody['get' + capitaliseFirstLetter(value)] = (() => {
return () => {
if (!Array.isArray(jsonBody[value])) {
if (jsonBody[value].includes(BASE_URL)) {
Expand Down Expand Up @@ -81,6 +81,8 @@ function parseOptions (options = {}) {
return options;
}

deprecate('Passing just an ID is deprecated. Use object form { id }');

return {
id: options
};
Expand Down
13 changes: 10 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
'use strict';

function deprecate (message) {
console.log(`DEPRECATION NOTICE: ${message}`);
}

function capitaliseFirstLetter (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

module.exports = {
capitaliseFirstLetter (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
deprecate,
capitaliseFirstLetter
};

0 comments on commit 87dba0a

Please sign in to comment.