@neoimpulse/cap-js-trim
A CAP plugin that strips whitespace from string elements on write, driven by a @cds.trim annotation on an entity or on single elements.
Facts
Where it sits
Who is behind it
In the atlas: maintains 7@neoimpulseGmbHmaintainerpatimwepneoContributes to this
In the atlas: contributes to 1@patimwepneo1 contributor
Before choosing this
Conditions
LicenceSAP Developer License Agreement 3.2 CAP§ 1, 2, 3A cds-plugin is used with SAP CAP materials, or an artifact is explicitly identified as a CAP plugin or application.
- § 1 License. Productive customer applications are limited to SAP BTP or another SAP-licensed platform, and mass extraction to a non-SAP product is restricted except where solely required for SAP interoperability.
- § 2 Intellectual Property. The agreement retains SAP's rights in the covered materials and limits making APIs, tools or software available to third parties, while preserving ownership of customer applications subject to SAP's underlying rights.
- § 3 Artificial Intelligence Training. The agreement prohibits use of the covered materials and customer applications for training artificial-intelligence models or systems.
What it declares
Every artifact
- Type
- CDS plugin
- Origin
- Independently maintained
- Runtime
- Node.js
As a CDS plugin
- Declared for
- >=9
- Distributed through
- npm
Connections
Making stored values consistent regardless of how they were typed
Download
Install
npm add @neoimpulse/cap-js-trimDerived from the package name. No recipe recorded; the README has the configuration.
README
quoted from neoimpulseGmbH/cap-js-trim under Apache-2.0, readCDS Trim Plugin
This plugin for the SAP Cloud Application Programming Model (CAP) automatically trims string attributes. The trim logic is applied based on annotations either on the entire entity or specific attributes.
Features
- Automatically trims all string attributes for entities annotated with
@cds.trim. - Trims specific string attributes annotated with
@cds.trim.
Installation
To install the plugin, add it to your CAP project.
npm install cds-trim-plugin
Usage
-
Annotate Your Model
Add the
@cds.trimannotation to your entities or specific attributes that should be trimmed.namespace my.bookshop; entity Books { key ID : Integer; title : String @cds.trim; author : String @cds.trim; } entity Authors @cds.trim { key ID : Integer; name : String; }
How It Works
The plugin scans all services and entities for the @cds.trim annotation. If an entity or its attributes are annotated, the plugin will automatically trim whitespace from string attributes before CREATE, UPDATE, and PATCH operations.
const cds = require("@sap/cds");
cds.once("served", () => {
for (let srv of cds.services) {
if (!(srv instanceof cds.ApplicationService)) continue;
for (let entity of srv.entities) {
if (entity["@cds.trim"]) {
srv.before(["CREATE", "UPDATE", "PATCH"], entity, (req) => {
for (const key in req.data) {
if (
req.data[key] &&
req.data[key] !== null &&
typeof req.data[key] === "string" &&
req.data[key] !== ""
) {
req.data[key] = req.data[key].trim();
}
}
});
} else {
for (const key in entity.elements) {
const element = entity.elements[key];
if (element.type === "cds.String" && element["@cds.trim"]) {
srv.before(["CREATE", "UPDATE", "PATCH"], entity, (req) => {
if (req.data[key] && typeof req.data[key] === "string" && req.data[key] !== "") {
req.data[key] = req.data[key].trim();
}
});
}
}
}
}
}
});
License
This project is licensed under the Apache License 2.0. See the LICENSE file for more details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
Thanks to the SAP CAP community for their support and contributions.
History
Others providing
Compare all 2 on the Value normalisation page →- @neoimpulse/cap-js-uppercase@neoimpulse/cap-js-uppercaseA CAP plugin that uppercases string elements on write, driven by a @cds.uppercase annotation on an entity or on single elements, the twin of the trim plugin.independent, capCAP plugin uppercasing strings on write via @cds.uppercase
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
Contributors
History in the atlas
- First seen.
For your agent
- Ref
artifact:neoimpulse-cap-js-trim- JSON
- /artifacts/neoimpulse-cap-js-trim.json
- MCP
- Connecting an agent