-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7333 from Automattic/5.4
5.4
- Loading branch information
Showing
42 changed files
with
2,134 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.