Move basicType to lib/helpers

Move the basicType function from the config lib to a shared helpers lib.
This commit is contained in:
Hornwitser committed 2020-04-03 20:51:28 +02:00
1 parent f05100c94d
commit 65494a0a91
3 files changed
+42 -15

No files matched your search

+2 -15
View File
@@ -4,6 +4,8 @@
*/
"use strict";
const { basicType } = require("lib/helpers");
/**
* Invalid Value exception
@@ -39,21 +41,6 @@ function splitOn(separator, string) {
return [string.slice(0, index), string.slice(index + separator.length)];
}
/**
* Return a string describing the type of the value passed
*
* Works the same as typeof, excpet that null and array types get their
* own string.
*
* @param value - value to return the type of.
* @returns {string} basic type of the value passed.
*/
function basicType(value) {
if (value === null) { return "null"; }
if (value instanceof Array) { return "array"; }
return typeof value;
}
/**
* Collection of config groups
*
+23
View File
@@ -0,0 +1,23 @@
/**
* Collection of small utilites that are useful in multiple places.
* @module
*/
/**
* Return a string describing the type of the value passed
*
* Works the same as typeof, excpet that null and array types get their
* own string.
*
* @param value - value to return the type of.
* @returns {string} basic type of the value passed.
*/
function basicType(value) {
if (value === null) { return "null"; }
if (value instanceof Array) { return "array"; }
return typeof value;
}
module.exports = {
basicType,
}
+17
View File
@@ -0,0 +1,17 @@
const assert = require("assert").strict;
const helpers = require("lib/helpers");
describe("lib/helpers", function() {
describe("basicType()", function() {
it("should return the expected values", function() {
assert.equal(helpers.basicType("s"), "string");
assert.equal(helpers.basicType(null), "null");
assert.equal(helpers.basicType(undefined), "undefined");
assert.equal(helpers.basicType([1, 2]), "array");
assert.equal(helpers.basicType(7), "number");
assert.equal(helpers.basicType({ a: 1 }), "object");
});
});
});