Remove all string object references (#586)

This commit is contained in:
Schuyler Cebulskie
2016-09-03 11:58:28 -04:00
committed by Amish Shah
parent ec0a5cdfbc
commit d97ce2e181
10 changed files with 19 additions and 23 deletions

View File

@@ -10,10 +10,6 @@ const Guild = getStructure('Guild');
const Channel = getStructure('Channel');
const GuildMember = getStructure('GuildMember');
function $string(obj) {
return (typeof obj === 'string' || obj instanceof String);
}
/**
* The DataResolver identifies different objects and tries to resolve a specific piece of information from them, e.g.
* extracting a User from a Message object.
@@ -31,7 +27,7 @@ class ClientDataResolver {
* * A Message (resolves to the message author)
* * A Guild (owner of the guild)
* * A Guild Member
* @typedef {User|String|Message|Guild|GuildMember} UserResolvable
* @typedef {User|string|Message|Guild|GuildMember} UserResolvable
*/
/**
@@ -42,7 +38,7 @@ class ClientDataResolver {
resolveUser(user) {
if (user instanceof User) {
return user;
} else if ($string(user)) {
} else if (typeof user === 'string') {
return this.client.users.get(user);
} else if (user instanceof Message) {
return user.author;
@@ -105,7 +101,7 @@ class ClientDataResolver {
/**
* Data that resolves to give a Base64 string, typically for image uploading. This can be:
* * A Buffer
* * A Base64 String
* * A Base64 string
* @typedef {Buffer|string} Base64Resolvable
*/
@@ -139,7 +135,7 @@ class ClientDataResolver {
return channel;
}
if ($string(channel)) {
if (typeof channel === 'string') {
return this.client.channels.get(channel.id);
}
@@ -147,20 +143,20 @@ class ClientDataResolver {
}
/**
* Data that can be resolved to give a String. This can be:
* * A String
* Data that can be resolved to give a string. This can be:
* * A string
* * An Array (joined with a new line delimiter to give a string)
* * Any object
* @typedef {string|Array|Object} StringResolvable
*/
/**
* Resolves a StringResolvable to a String
* Resolves a StringResolvable to a string
* @param {StringResolvable} StringResolvable the string resolvable to resolve
* @returns {string}
*/
resolveString(data) {
if (data instanceof String) {
if (typeof data === 'string') {
return data;
}
@@ -185,7 +181,7 @@ class ClientDataResolver {
* @returns {string|Buffer}
*/
resolveFile(resource) {
if ($string(resource)) {
if (typeof resource === 'string') {
return new Promise((resolve, reject) => {
if (/^https?:\/\//.test(resource)) {
request.get(resource)

View File

@@ -464,7 +464,7 @@ class RESTMethods {
if (_data.permissions) {
let perms = 0;
for (let perm of _data.permissions) {
if (perm instanceof String || typeof perm === 'string') {
if (typeof perm === 'string') {
perm = Constants.PermissionFlags[perm];
}
perms |= perm;

View File

@@ -31,7 +31,7 @@ class DMChannel extends Channel {
}
/**
* When concatenated with a String, this automatically concatenates the recipient's mention instead of the
* When concatenated with a string, this automatically concatenates the recipient's mention instead of the
* DM channel object.
* @returns {string}
*/

View File

@@ -68,7 +68,7 @@ class Emoji {
}
/**
* When concatenated with a String, this automatically returns the emoji mention rather than the object.
* When concatenated with a string, this automatically returns the emoji mention rather than the object.
* @returns {string}
* @example
* // send an emoji:

View File

@@ -39,7 +39,7 @@ class EvaluatedPermissions {
* @returns {boolean}
*/
hasPermission(permission, explicit = false) {
if (permission instanceof String || typeof permission === 'string') {
if (typeof permission === 'string') {
permission = Constants.PermissionFlags[permission];
}

View File

@@ -151,7 +151,7 @@ class Guild {
}
/**
* When concatenated with a String, this automatically concatenates the Guild's name instead of the Guild object.
* When concatenated with a string, this automatically concatenates the Guild's name instead of the Guild object.
* @returns {string}
* @example
* // logs: Hello from My Guild!

View File

@@ -263,7 +263,7 @@ class GuildChannel extends Channel {
}
/**
* When concatenated with a String, this automatically returns the Channel's mention instead of the Channel object.
* When concatenated with a string, this automatically returns the Channel's mention instead of the Channel object.
* @returns {string}
* @example
* // Outputs: Hello from #general

View File

@@ -198,7 +198,7 @@ class Role {
* }
*/
hasPermission(permission, explicit = false) {
if (permission instanceof String || typeof permission === 'string') {
if (typeof permission === 'string') {
permission = Constants.PermissionFlags[permission];
}
@@ -216,7 +216,7 @@ class Role {
}
/**
* When concatenated with a String, this automatically concatenates the Role mention rather than the Role object.
* When concatenated with a string, this automatically concatenates the Role mention rather than the Role object.
* @returns {string}
*/
toString() {

View File

@@ -56,7 +56,7 @@ class User {
}
/**
* When concatenated with a String, this automatically concatenates the User's mention instead of the User object.
* When concatenated with a string, this automatically concatenates the User's mention instead of the User object.
* @returns {string}
* @example
* // logs: Hello from <@123456789>!

View File

@@ -196,7 +196,7 @@ class TextBasedChannel {
*/
sendFile(attachment, fileName) {
if (!fileName) {
if (attachment instanceof String || typeof attachment === 'string') {
if (typeof attachment === 'string') {
fileName = path.basename(attachment);
} else if (attachment && attachment.path) {
fileName = path.basename(attachment.path);