Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
25fa25a251 | |||
13ca1037d2 | |||
8f072ad217 | |||
93b159b695 | |||
72145abaf9 | |||
cef31966f9 | |||
f0e981e13e |
@ -13,8 +13,13 @@ stages:
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
- pnpm install -g pnpm
|
||||
- pnpm install -g @shipzone/npmci
|
||||
- npmci npm prepare
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
@ -22,11 +27,10 @@ auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --prod
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
@ -34,11 +38,10 @@ auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
- npmci command pnpm audit --audit-level=high --dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
@ -49,7 +52,6 @@ auditDevDependencies:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
@ -60,10 +62,9 @@ testStable:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
@ -111,8 +112,7 @@ trigger:
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
|
@ -2,17 +2,33 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartvalidator",
|
||||
"description": "a wrapper for the validator package to perform validations",
|
||||
"npmPackagename": "@pushrocks/smartvalidator",
|
||||
"description": "A wrapper for performing validations using the validator package.",
|
||||
"npmPackagename": "@push.rocks/smartvalidator",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
"projectDomain": "push.rocks",
|
||||
"keywords": [
|
||||
"validation",
|
||||
"validator wrapper",
|
||||
"data sanitation",
|
||||
"input validation",
|
||||
"type checking",
|
||||
"security",
|
||||
"form validation",
|
||||
"string validation",
|
||||
"URL validation",
|
||||
"IBAN validation",
|
||||
"email escape"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
11282
package-lock.json
generated
11282
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "@pushrocks/smartvalidator",
|
||||
"version": "1.0.4",
|
||||
"name": "@push.rocks/smartvalidator",
|
||||
"version": "1.0.5",
|
||||
"private": false,
|
||||
"description": "a wrapper for the validator package to perform validations",
|
||||
"description": "A wrapper for performing validations using the validator package.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
@ -19,7 +19,7 @@
|
||||
"@gitzone/tsdoc": "^1.1.10",
|
||||
"@gitzone/tstest": "^1.0.44",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^17.0.41"
|
||||
"@types/node": "^18.15.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/validator": "^13.7.4",
|
||||
@ -39,5 +39,23 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"validation",
|
||||
"validator wrapper",
|
||||
"data sanitation",
|
||||
"input validation",
|
||||
"type checking",
|
||||
"security",
|
||||
"form validation",
|
||||
"string validation",
|
||||
"URL validation",
|
||||
"IBAN validation",
|
||||
"email escape"
|
||||
],
|
||||
"homepage": "https://code.foss.global/push.rocks/smartvalidator",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartvalidator.git"
|
||||
}
|
||||
}
|
4550
pnpm-lock.yaml
generated
Normal file
4550
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
135
readme.md
135
readme.md
@ -1,39 +1,120 @@
|
||||
# @pushrocks/smartvalidator
|
||||
# @push.rocks/smartvalidator
|
||||
a wrapper for the validator package to perform validations
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartvalidator)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartvalidator)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartvalidator)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartvalidator/)
|
||||
## Install
|
||||
To use `@push.rocks/smartvalidator` in your project, installation via npm or yarn is straightforward. Run the following command in your project directory:
|
||||
|
||||
## Status for master
|
||||
```bash
|
||||
npm install @push.rocks/smartvalidator --save
|
||||
```
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
or if you prefer using yarn:
|
||||
|
||||
```bash
|
||||
yarn add @push.rocks/smartvalidator
|
||||
```
|
||||
|
||||
This will download the package and add it to your `node_modules` folder as well as list it as a dependency in your `package.json` file.
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class intellisense
|
||||
`@push.rocks/smartvalidator` serves as a convenient wrapper around the popular [`validator`](https://www.npmjs.com/package/validator) library, providing you with additional utilities and simplifications for validation tasks. Below is a comprehensive guide on how to leverage `@push.rocks/smartvalidator` effectively in your TypeScript project.
|
||||
|
||||
## Contribution
|
||||
First, ensure that your module system supports ECMAScript Modules (ESM) syntax and that you have TypeScript configured in your project.
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
### Getting Started
|
||||
To begin, import `SmartValidator` from the package:
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
```typescript
|
||||
import { SmartValidator } from '@push.rocks/smartvalidator';
|
||||
```
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
Create an instance of `SmartValidator`:
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
```typescript
|
||||
const validator = new SmartValidator();
|
||||
```
|
||||
|
||||
### Validating an IBAN
|
||||
Validating an International Bank Account Number (IBAN) is straightforward:
|
||||
|
||||
```typescript
|
||||
const iban = 'AT95 0100 0000 0555 4915';
|
||||
if (validator.isIban(iban)) {
|
||||
console.log('The IBAN is valid.');
|
||||
} else {
|
||||
console.log('The IBAN is invalid.');
|
||||
}
|
||||
```
|
||||
|
||||
### Checking URLs
|
||||
To check if a string is a valid URL:
|
||||
|
||||
```typescript
|
||||
const url = 'https://example.com';
|
||||
if (validator.isUrl(url)) {
|
||||
console.log('The URL is valid.');
|
||||
} else {
|
||||
console.log('The URL is invalid.');
|
||||
}
|
||||
```
|
||||
|
||||
### Escaping Strings
|
||||
When you need to escape strings, for instance, to sanitize input data:
|
||||
|
||||
```typescript
|
||||
const userInput = '<script>alert("xss")</script>';
|
||||
const escapedInput = validator.escape(userInput);
|
||||
console.log(escapedInput); // Output will have HTML special characters escaped
|
||||
```
|
||||
|
||||
### Checking CSV Strings
|
||||
You can check if a string could potentially be interpreted as CSV data:
|
||||
|
||||
```typescript
|
||||
const csvString = 'name,age,city\nJohn Doe,29,New York';
|
||||
if (validator.isCsv(csvString)) {
|
||||
console.log('The string is likely a CSV data.');
|
||||
} else {
|
||||
console.log('The string is unlikely to be CSV data.');
|
||||
}
|
||||
```
|
||||
|
||||
### Underlying Validator Access
|
||||
The underlying `validator` library can be accessed directly if you need functionalities not directly exposed by `SmartValidator`:
|
||||
|
||||
```typescript
|
||||
const email = 'example@example.com';
|
||||
if (SmartValidator.validator.isEmail(email)) {
|
||||
console.log('The email address is valid.');
|
||||
} else {
|
||||
console.log('The email address is invalid.');
|
||||
}
|
||||
```
|
||||
|
||||
### Additional Notes
|
||||
- Keep in mind that while `@push.rocks/smartvalidator` simplifies certain tasks, not all functionalities of the `validator` library are wrapped. Access the original validator object for advanced use cases.
|
||||
- For contributions or issues, please refer to the project's GitHub repository.
|
||||
|
||||
**Note**: The usage examples shown above cover basic usage and common validation tasks. For more complex use cases, feel free to explore the original `validator` library's [documentation](https://www.npmjs.com/package/validator) as `@push.rocks/smartvalidator` simply extends its capabilities.
|
||||
|
||||
By integrating `@push.rocks/smartvalidator` into your project, you leverage a streamlined, typed interface for data validation, enhancing both development experience and code maintainability.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
@ -8,6 +8,10 @@ tap.test('first test', async () => {
|
||||
expect(testValidator).toBeInstanceOf(smartvalidator.SmartValidator);
|
||||
});
|
||||
|
||||
tap.test('should check for being a URL', async () => {
|
||||
expect(testValidator.isUrl('lossless.com')).toBeTrue();
|
||||
})
|
||||
|
||||
tap.test('should check an IBAN', async () => {
|
||||
expect(testValidator.isIban('AT95 0100 0000 0555 4915')).toBeTrue();
|
||||
});
|
||||
@ -15,6 +19,6 @@ tap.test('should check an IBAN', async () => {
|
||||
tap.test('escape email', async () => {
|
||||
const escapedEmail = testValidator.escape('test@example.com');
|
||||
console.log(escapedEmail);
|
||||
})
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartvalidator',
|
||||
version: '1.0.4',
|
||||
version: '1.0.5',
|
||||
description: 'a wrapper for the validator package to perform validations'
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ export class SmartValidator {
|
||||
/**
|
||||
* might be buggy. TODO: Improve.
|
||||
* @param stringArg
|
||||
* @returns
|
||||
* @returns
|
||||
*/
|
||||
public isCsv(stringArg: string) {
|
||||
return stringArg.split(',').length > 4 || stringArg.split(';').length > 4;
|
||||
|
@ -2,6 +2,4 @@ import validatorMod from 'validator';
|
||||
|
||||
const validator: typeof validatorMod.default = validatorMod as any;
|
||||
|
||||
export {
|
||||
validator
|
||||
}
|
||||
export { validator };
|
||||
|
@ -3,8 +3,12 @@
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user