summaryrefslogtreecommitdiffstats
path: root/node_modules/mongoose/lib/cast
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/mongoose/lib/cast')
-rw-r--r--node_modules/mongoose/lib/cast/boolean.js32
-rw-r--r--node_modules/mongoose/lib/cast/date.js41
-rw-r--r--node_modules/mongoose/lib/cast/decimal128.js36
-rw-r--r--node_modules/mongoose/lib/cast/number.js43
-rw-r--r--node_modules/mongoose/lib/cast/objectid.js29
-rw-r--r--node_modules/mongoose/lib/cast/string.js37
6 files changed, 0 insertions, 218 deletions
diff --git a/node_modules/mongoose/lib/cast/boolean.js b/node_modules/mongoose/lib/cast/boolean.js
deleted file mode 100644
index 92551d4..0000000
--- a/node_modules/mongoose/lib/cast/boolean.js
+++ /dev/null
@@ -1,32 +0,0 @@
-'use strict';
-
-const CastError = require('../error/cast');
-
-/*!
- * Given a value, cast it to a boolean, or throw a `CastError` if the value
- * cannot be casted. `null` and `undefined` are considered valid.
- *
- * @param {Any} value
- * @param {String} [path] optional the path to set on the CastError
- * @return {Boolean|null|undefined}
- * @throws {CastError} if `value` is not one of the allowed values
- * @api private
- */
-
-module.exports = function castBoolean(value, path) {
- if (module.exports.convertToTrue.has(value)) {
- return true;
- }
- if (module.exports.convertToFalse.has(value)) {
- return false;
- }
-
- if (value == null) {
- return value;
- }
-
- throw new CastError('boolean', value, path);
-};
-
-module.exports.convertToTrue = new Set([true, 'true', 1, '1', 'yes']);
-module.exports.convertToFalse = new Set([false, 'false', 0, '0', 'no']);
diff --git a/node_modules/mongoose/lib/cast/date.js b/node_modules/mongoose/lib/cast/date.js
deleted file mode 100644
index ac17006..0000000
--- a/node_modules/mongoose/lib/cast/date.js
+++ /dev/null
@@ -1,41 +0,0 @@
-'use strict';
-
-const assert = require('assert');
-
-module.exports = function castDate(value) {
- // Support empty string because of empty form values. Originally introduced
- // in https://github.com/Automattic/mongoose/commit/efc72a1898fc3c33a319d915b8c5463a22938dfe
- if (value == null || value === '') {
- return null;
- }
-
- if (value instanceof Date) {
- assert.ok(!isNaN(value.valueOf()));
-
- return value;
- }
-
- let date;
-
- assert.ok(typeof value !== 'boolean');
-
- if (value instanceof Number || typeof value === 'number') {
- date = new Date(value);
- } else if (typeof value === 'string' && !isNaN(Number(value)) && (Number(value) >= 275761 || Number(value) < -271820)) {
- // string representation of milliseconds take this path
- date = new Date(Number(value));
- } else if (typeof value.valueOf === 'function') {
- // support for moment.js. This is also the path strings will take because
- // strings have a `valueOf()`
- date = new Date(value.valueOf());
- } else {
- // fallback
- date = new Date(value);
- }
-
- if (!isNaN(date.valueOf())) {
- return date;
- }
-
- assert.ok(false);
-}; \ No newline at end of file
diff --git a/node_modules/mongoose/lib/cast/decimal128.js b/node_modules/mongoose/lib/cast/decimal128.js
deleted file mode 100644
index bfb1578..0000000
--- a/node_modules/mongoose/lib/cast/decimal128.js
+++ /dev/null
@@ -1,36 +0,0 @@
-'use strict';
-
-const Decimal128Type = require('../types/decimal128');
-const assert = require('assert');
-
-module.exports = function castDecimal128(value) {
- if (value == null) {
- return value;
- }
-
- if (typeof value === 'object' && typeof value.$numberDecimal === 'string') {
- return Decimal128Type.fromString(value.$numberDecimal);
- }
-
- if (value instanceof Decimal128Type) {
- return value;
- }
-
- if (typeof value === 'string') {
- return Decimal128Type.fromString(value);
- }
-
- if (Buffer.isBuffer(value)) {
- return new Decimal128Type(value);
- }
-
- if (typeof value === 'number') {
- return Decimal128Type.fromString(String(value));
- }
-
- if (typeof value.valueOf === 'function' && typeof value.valueOf() === 'string') {
- return Decimal128Type.fromString(value.valueOf());
- }
-
- assert.ok(false);
-}; \ No newline at end of file
diff --git a/node_modules/mongoose/lib/cast/number.js b/node_modules/mongoose/lib/cast/number.js
deleted file mode 100644
index 7cd7f84..0000000
--- a/node_modules/mongoose/lib/cast/number.js
+++ /dev/null
@@ -1,43 +0,0 @@
-'use strict';
-
-const assert = require('assert');
-
-/*!
- * Given a value, cast it to a number, or throw a `CastError` if the value
- * cannot be casted. `null` and `undefined` are considered valid.
- *
- * @param {Any} value
- * @param {String} [path] optional the path to set on the CastError
- * @return {Boolean|null|undefined}
- * @throws {Error} if `value` is not one of the allowed values
- * @api private
- */
-
-module.exports = function castNumber(val) {
- if (val == null) {
- return val;
- }
- if (val === '') {
- return null;
- }
-
- if (typeof val === 'string' || typeof val === 'boolean') {
- val = Number(val);
- }
-
- assert.ok(!isNaN(val));
- if (val instanceof Number) {
- return val.valueOf();
- }
- if (typeof val === 'number') {
- return val;
- }
- if (!Array.isArray(val) && typeof val.valueOf === 'function') {
- return Number(val.valueOf());
- }
- if (val.toString && !Array.isArray(val) && val.toString() == Number(val)) {
- return Number(val);
- }
-
- assert.ok(false);
-};
diff --git a/node_modules/mongoose/lib/cast/objectid.js b/node_modules/mongoose/lib/cast/objectid.js
deleted file mode 100644
index 67cffb5..0000000
--- a/node_modules/mongoose/lib/cast/objectid.js
+++ /dev/null
@@ -1,29 +0,0 @@
-'use strict';
-
-const ObjectId = require('../driver').get().ObjectId;
-const assert = require('assert');
-
-module.exports = function castObjectId(value) {
- if (value == null) {
- return value;
- }
-
- if (value instanceof ObjectId) {
- return value;
- }
-
- if (value._id) {
- if (value._id instanceof ObjectId) {
- return value._id;
- }
- if (value._id.toString instanceof Function) {
- return new ObjectId(value._id.toString());
- }
- }
-
- if (value.toString instanceof Function) {
- return new ObjectId(value.toString());
- }
-
- assert.ok(false);
-}; \ No newline at end of file
diff --git a/node_modules/mongoose/lib/cast/string.js b/node_modules/mongoose/lib/cast/string.js
deleted file mode 100644
index 4d89f8e..0000000
--- a/node_modules/mongoose/lib/cast/string.js
+++ /dev/null
@@ -1,37 +0,0 @@
-'use strict';
-
-const CastError = require('../error/cast');
-
-/*!
- * Given a value, cast it to a string, or throw a `CastError` if the value
- * cannot be casted. `null` and `undefined` are considered valid.
- *
- * @param {Any} value
- * @param {String} [path] optional the path to set on the CastError
- * @return {string|null|undefined}
- * @throws {CastError}
- * @api private
- */
-
-module.exports = function castString(value, path) {
- // If null or undefined
- if (value == null) {
- return value;
- }
-
- // handle documents being passed
- if (value._id && typeof value._id === 'string') {
- return value._id;
- }
-
- // Re: gh-647 and gh-3030, we're ok with casting using `toString()`
- // **unless** its the default Object.toString, because "[object Object]"
- // doesn't really qualify as useful data
- if (value.toString &&
- value.toString !== Object.prototype.toString &&
- !Array.isArray(value)) {
- return value.toString();
- }
-
- throw new CastError('string', value, path);
-};