-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suppresswarnings now covers user props
- Loading branch information
1 parent
f516128
commit 887be93
Showing
3 changed files
with
37 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
|
||
|
||
module.exports.suppressWarnings = function () { | ||
module.exports.suppressWarnings = (function () { | ||
const _ignoreList = [] | ||
let initialized = false | ||
const _warn = console.warn | ||
console.warn = function (...params) { | ||
const msg = params[0] | ||
const ignores = ['scoped', 'route', 'routes', 'url'] | ||
|
||
const match = ignores.filter(prop => msg.match(new RegExp(`was created with unknown prop '${prop}'`))).length | ||
if (!match) | ||
_warn(...params) | ||
return function (newIgnores = []) { | ||
newIgnores.forEach(key => { | ||
if (!_ignoreList.includes(key)) | ||
_ignoreList.push(key) | ||
}) | ||
|
||
if (!initialized) { | ||
initialized = true | ||
console.warn = function (...params) { | ||
const msg = params[0] | ||
const match = _ignoreList.filter(prop => msg.match(new RegExp(`was created with unknown prop '${prop}'`))).length | ||
if (!match) | ||
_warn(...params) | ||
} | ||
} | ||
} | ||
} | ||
})() | ||
|
||
module.exports.demandObject = function (obj) { | ||
const isObj = Object.prototype.toString.call(obj) === "[object Object]"; | ||
if (isObj || !obj) return true; | ||
else | ||
throw new Error( | ||
`"${obj}" is not an object. "scoped" prop must an object` | ||
); | ||
} |