diff --git a/core/loadServer.js b/core/loadServer.js index c7d62bf..2e07aca 100644 --- a/core/loadServer.js +++ b/core/loadServer.js @@ -16,6 +16,7 @@ import csrf from 'csurf'; import SaplingError from '../lib/SaplingError.js'; import Response from '../lib/Response.js'; import Cluster from '../lib/Cluster.js'; +import Utils from '../lib/Utils.js'; /** @@ -73,9 +74,7 @@ export default function loadServer({ reload, listen }, next) { /* Handle the directory for our static resources */ if ('publicDir' in this.config) { /* If it's a string, coerce into an array */ - if (Array.isArray(this.config.publicDir) === false) { - this.config.publicDir = [this.config.publicDir]; - } + this.config.publicDir = new Utils().coerceArray(this.config.publicDir); /* Loop through it */ for (const publicDir of this.config.publicDir) { diff --git a/drivers/db/Memory.js b/drivers/db/Memory.js index babf988..75108b7 100644 --- a/drivers/db/Memory.js +++ b/drivers/db/Memory.js @@ -174,12 +174,7 @@ export default class Memory extends Interface { continue; } - let condition = conditions[field]; - - /* Coerce into an array */ - if (Array.isArray(condition) === false) { - condition = [condition]; - } + const condition = new Utils().coerceArray(conditions[field]); match = condition.some(value => { /* If it's an ID, do an exact match always */ diff --git a/lib/Response.js b/lib/Response.js index 5916f20..470c430 100644 --- a/lib/Response.js +++ b/lib/Response.js @@ -12,6 +12,7 @@ import isobject from 'isobject'; import { console } from './Cluster.js'; import Redirect from './Redirect.js'; import Templating from './Templating.js'; +import Utils from './Utils.js'; /** @@ -70,9 +71,7 @@ export default class Response { } /* Coerce anything else into an array */ - if (!Array.isArray(array)) { - array = [array]; - } + array = new Utils().coerceArray(array); /* Whether the array contains objects or something else */ const notObject = array.length > 0 && !isobject(array[0]); diff --git a/lib/User.js b/lib/User.js index 01ff542..d8f9e29 100644 --- a/lib/User.js +++ b/lib/User.js @@ -9,6 +9,7 @@ import routeMatcher from 'path-match'; import Response from './Response.js'; import SaplingError from './SaplingError.js'; +import Utils from './Utils.js'; /** @@ -148,7 +149,7 @@ export default class User { const userType = permissionKey in this.app.permissions ? this.app.permissions[permissionKey].role : 'anyone'; /* Return the first match */ - return Array.isArray(userType) ? userType : [userType]; + return new Utils().coerceArray(userType); } }