@databases/escape-identifier
Advanced tools
Comparing version 1.0.2 to 1.0.3-canary-1737
@@ -11,3 +11,3 @@ "use strict"; | ||
function escapePostgresIdentifier(str, { extended = false } = {}) { | ||
validate_unicode_1.default(str); | ||
(0, validate_unicode_1.default)(str); | ||
minLength(str, 'Postgres'); | ||
@@ -30,3 +30,3 @@ maxLength(str, 60, 'Postgres', 'https://www.postgresql.org/docs/9.3/sql-syntax-lexical.html'); | ||
function escapeMySqlIdentifier(str, { extended = false } = {}) { | ||
validate_unicode_1.default(str); | ||
(0, validate_unicode_1.default)(str); | ||
minLength(str, 'MySQL'); | ||
@@ -55,3 +55,3 @@ maxLength(str, 64, 'MySQL', 'http://dev.mysql.com/doc/refman/5.7/en/identifiers.html'); | ||
function escapeSQLiteIdentifier(str) { | ||
validate_unicode_1.default(str); | ||
(0, validate_unicode_1.default)(str); | ||
minLength(str, 'SQLite'); | ||
@@ -66,15 +66,10 @@ if (str.length > 63) { | ||
function quoteString(str, quoteChar) { | ||
let escaped = quoteChar; | ||
for (const c of str) { | ||
if (c === quoteChar) | ||
escaped += c + c; | ||
else | ||
escaped += c; | ||
} | ||
escaped += quoteChar; | ||
return escaped; | ||
if (!str.includes(quoteChar)) | ||
return quoteChar + str + quoteChar; | ||
return (quoteChar + str.split(quoteChar).join(quoteChar + quoteChar) + quoteChar); | ||
} | ||
const NON_ASCII = /[^\u0001-\u007f]/; | ||
function assertAscii(str, db, unicodeAvailable) { | ||
if (!/^[\u0001-\u007f]+$/.test(str)) { | ||
throw new Error(`${db} identifiers may only contain ASCII characters${unicodeAvailable | ||
if (NON_ASCII.test(str)) { | ||
throw new Error(`${db} identifiers must only contain ASCII characters${unicodeAvailable | ||
? ` (to use unicode, pass {extended: true} when escaping the identifier)` | ||
@@ -84,7 +79,8 @@ : ``}`); | ||
} | ||
const NON_UNICODE = /[^\u0001-\uffff]/; | ||
function assertUnicode(str, db) { | ||
// U+0001 .. U+007F | ||
// U+0080 .. U+FFFF | ||
if (!/^[\u0001-\uffff]+$/.test(str)) { | ||
throw new Error(`${db} identifiers should only contain charcters in the range: U+0001 .. U+FFFF`); | ||
if (NON_UNICODE.test(str)) { | ||
throw new Error(`${db} identifiers must only contain characters in the range: U+0001 .. U+FFFF`); | ||
} | ||
@@ -99,5 +95,5 @@ } | ||
if (str.length > length) { | ||
throw new Error(`${db} identifiers should not be longer than ${length} characters. ${str}`); | ||
throw new Error(`${db} identifiers must not be longer than ${length} characters. ${str}`); | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@databases/escape-identifier", | ||
"version": "1.0.2", | ||
"version": "1.0.3-canary-1737", | ||
"description": "", | ||
@@ -8,3 +8,3 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@databases/validate-unicode": "^1.0.0" | ||
"@databases/validate-unicode": "1.0.0" | ||
}, | ||
@@ -11,0 +11,0 @@ "scripts": {}, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
155
51196
1