Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
sequelize-transformations
Advanced tools
Readme
Sequelize plugin to add configurable attribute transforms. It allows you to
define transformation functions to run on attribute values when an instance is updated (through assignment,
set
, build
, create
etc.). The transformation functions can be enabled and configured on attribute level.
npm install sequelize-transformations
To activate the plugin for all your models, call the plugin on your sequelize
instance:
var sequelizeTransformations = require('sequelize-transformations');
sequelizeTransformations(sequelize);
To use transformations for an attribute, just add them to its definition:
var Model = sequelize.define('Model', {
email: {
type: Sequelize.DataTypes.STRING,
lowercase: true,
trim: true
}
});
With this configuration, the email
attribute will always be trimmed and transformed to lower case.
The plugin comes with the following predefined transformations:
trim
: trim valuelowercase
: transform value to all lower caseuppercase
: transform value to all upper caseIt is possible to override predefined transformations or add your own by passing an object as the second argument:
sequelizeTransformations(sequelize, {
trim: function(val, defintion) {
return val.toString().replace(/ /g, '*');
},
append: function(val, definition) {
return val.toString() + definition['append'];
},
removeMilliseconds: function(val, definition) {
if(val) {
val.setMilliseconds(0);
}
return val;
}
});
This would override the trim
transform and add a new one called append
. Every transform function is called with
two parameters: the value to transform and the definition of the attribute being transformed.
lowercase
and uppercase
.raw
option set to true
, then the transforms will not be run.import {sequelizeTransformations, ModelAttributeDefinition, TransformationDefinitions} from "sequelizeTransformations";
type TransformationDefinitions = {
removeMilliseconds?: boolean;
}
sequelizeTransformations(sequelize, {
removeMilliseconds: function(date: Date, definition: ModelAttributeDefinition<TransformationDefinitions>) {
if(definition.removeMilliseconds) {
date?.setMilliseconds(0);
}
return date;
}
});
import {DataTypes, Optional} from "sequelize";
import {ModelAttributesWithTransformations} from "sequelize-transformations";
interface ModelAttributes {
id: number;
email: string;
}
interface ModelCreationAttributes extends Optional<ModelAttributes, "id"> {}
var Model = sequelize.define('Model', (<ModelAttributesWithTransformations<ModelCreationAttributes>>{
email: {
type: DataTypes.STRING,
lowercase: true,
trim: true
}
}));
FAQs
Sequelize plugin to add configurable attribute transformations.
The npm package sequelize-transformations receives a total of 0 weekly downloads. As such, sequelize-transformations popularity was classified as not popular.
We found that sequelize-transformations demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.