diff options
author | Joel Kronqvist <work.joelkronqvist@pm.me> | 2022-03-11 20:46:06 +0200 |
---|---|---|
committer | Joel Kronqvist <work.joelkronqvist@pm.me> | 2022-03-11 20:46:06 +0200 |
commit | 080c5819d87b933816d724a83f3bf4f1686770a7 (patch) | |
tree | 4a2ccc68b27edf7d4cbc586c932cc7542b655e19 /node_modules/mysql2/lib/helpers.js | |
parent | 5ac7049a9d30733165cc212dee308163c2a14644 (diff) | |
parent | d003b82235a9329f912522a2f70aa950dfce4998 (diff) | |
download | LYLLRuoka-080c5819d87b933816d724a83f3bf4f1686770a7.tar.gz LYLLRuoka-080c5819d87b933816d724a83f3bf4f1686770a7.zip |
Merge branch 'master' of https://github.com/JoelHMikael/FoodJS
Updating remote changes
Diffstat (limited to 'node_modules/mysql2/lib/helpers.js')
-rw-r--r-- | node_modules/mysql2/lib/helpers.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/node_modules/mysql2/lib/helpers.js b/node_modules/mysql2/lib/helpers.js new file mode 100644 index 0000000..b30939b --- /dev/null +++ b/node_modules/mysql2/lib/helpers.js @@ -0,0 +1,63 @@ +'use strict'; + +/* + + this seems to be not only shorter, but faster than + string.replace(/\\/g, '\\\\'). + replace(/\u0008/g, '\\b'). + replace(/\t/g, '\\t'). + replace(/\n/g, '\\n'). + replace(/\f/g, '\\f'). + replace(/\r/g, '\\r'). + replace(/'/g, '\\\''). + replace(/"/g, '\\"'); + or string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + see http://jsperf.com/string-escape-regexp-vs-json-stringify + */ +function srcEscape(str) { + return JSON.stringify({ + [str]: 1 + }).slice(1, -3); +} + +exports.srcEscape = srcEscape; + +let highlightFn; +let cardinalRecommended = false; +try { + highlightFn = require('cardinal').highlight; +} catch (err) { + highlightFn = text => { + if (!cardinalRecommended) { + // eslint-disable-next-line no-console + console.log('For nicer debug output consider install cardinal@^2.0.0'); + cardinalRecommended = true; + } + return text; + }; +} + +/** + * Prints debug message with code frame, will try to use `cardinal` if available. + */ +function printDebugWithCode(msg, code) { + // eslint-disable-next-line no-console + console.log(`\n\n${msg}:\n`); + // eslint-disable-next-line no-console + console.log(`${highlightFn(code)}\n`); +} + +exports.printDebugWithCode = printDebugWithCode; + +/** + * checks whether the `type` is in the `list` + */ +function typeMatch(type, list, Types) { + if (Array.isArray(list)) { + return list.some(t => type === Types[t]); + } + + return !!list; +} + +exports.typeMatch = typeMatch; |