Move stripNullByte and processData from models/index.ts to utils.ts

Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
David Mehren 2020-04-11 11:22:55 +02:00
parent 03ae37055d
commit 8c662a1f41
No known key found for this signature in database
GPG key ID: 6017AF117F9756CB
2 changed files with 32 additions and 42 deletions

View file

@ -24,6 +24,30 @@ export module Utils {
}
}
// [Postgres] Handling NULL bytes
// https://github.com/sequelize/sequelize/issues/6485
export function stripNullByte(value) {
value = '' + value
// eslint-disable-next-line no-control-regex
return value ? value.replace(/\u0000/g, '') : value
}
export function processData (data, _default, process?) {
if (data === undefined) return data
else if (process) {
if (data === null) {
return _default
} else {
return process(data)
}
} else {
if (data === null) {
return _default
} else {
return data
}
}
}
}