@astral/validations 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/createRule/createRule.d.ts +6 -0
- package/createRule/createRule.js +9 -0
- package/createRule/createRule.test.d.ts +1 -0
- package/createRule/createRule.test.js +9 -0
- package/createRule/index.d.ts +1 -0
- package/createRule/index.js +17 -0
- package/esm/createRule/createRule.d.ts +6 -0
- package/esm/createRule/createRule.js +5 -0
- package/esm/createRule/createRule.test.d.ts +1 -0
- package/esm/createRule/createRule.test.js +7 -0
- package/esm/createRule/index.d.ts +1 -0
- package/esm/createRule/index.js +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/isString/index.d.ts +1 -0
- package/esm/isString/index.js +1 -0
- package/esm/isString/isString.d.ts +6 -0
- package/esm/isString/isString.js +12 -0
- package/esm/isString/isString.test.d.ts +1 -0
- package/esm/isString/isString.test.js +13 -0
- package/esm/types.d.ts +1 -0
- package/esm/types.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +17 -0
- package/isString/index.d.ts +1 -0
- package/isString/index.js +17 -0
- package/isString/isString.d.ts +6 -0
- package/isString/isString.js +15 -0
- package/isString/isString.test.d.ts +1 -0
- package/isString/isString.test.js +15 -0
- package/package.json +22 -0
- package/types.d.ts +1 -0
- package/types.js +2 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Astral.Soft
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
import { Rule } from '../types';
|
2
|
+
/**
|
3
|
+
* @example createRule((max: number, message: string) => value => value > max ? message : undefined)
|
4
|
+
* @description Фабрика по созданию правил валидации.
|
5
|
+
*/
|
6
|
+
export declare const createRule: <Args extends unknown[]>(creator: Rule<Args>) => Rule<Args>;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createRule = void 0;
|
4
|
+
/**
|
5
|
+
* @example createRule((max: number, message: string) => value => value > max ? message : undefined)
|
6
|
+
* @description Фабрика по созданию правил валидации.
|
7
|
+
*/
|
8
|
+
var createRule = function (creator) { return creator; };
|
9
|
+
exports.createRule = createRule;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
var createRule_1 = require("./createRule");
|
4
|
+
describe('createRule', function () {
|
5
|
+
it('Не модифицирует переданный rule', function () {
|
6
|
+
var rule = (0, createRule_1.createRule)(function () { return function () { return 'Ошибка'; }; });
|
7
|
+
expect(rule()()).toBe('Ошибка');
|
8
|
+
});
|
9
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './createRule';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./createRule"), exports);
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { Rule } from '../types';
|
2
|
+
/**
|
3
|
+
* @example createRule((max: number, message: string) => value => value > max ? message : undefined)
|
4
|
+
* @description Фабрика по созданию правил валидации.
|
5
|
+
*/
|
6
|
+
export declare const createRule: <Args extends unknown[]>(creator: Rule<Args>) => Rule<Args>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './createRule';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './createRule';
|
package/esm/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './createRule';
|
package/esm/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './createRule';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isString';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isString';
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export declare const STRING_RULE_MESSAGE = "\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u043E\u0439";
|
2
|
+
/**
|
3
|
+
* @example isString('Не строка')('string')
|
4
|
+
* @description Правило проверки на строку.
|
5
|
+
*/
|
6
|
+
export declare const isString: import("../types").Rule<[message?: string | undefined]>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { createRule } from '../createRule';
|
2
|
+
export var STRING_RULE_MESSAGE = 'Должно быть строкой';
|
3
|
+
/**
|
4
|
+
* @example isString('Не строка')('string')
|
5
|
+
* @description Правило проверки на строку.
|
6
|
+
*/
|
7
|
+
export var isString = createRule(function (message) {
|
8
|
+
if (message === void 0) { message = STRING_RULE_MESSAGE; }
|
9
|
+
return function (value) {
|
10
|
+
return typeof value === 'string' ? undefined : message;
|
11
|
+
};
|
12
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { STRING_RULE_MESSAGE, isString } from './isString';
|
2
|
+
describe('isString', function () {
|
3
|
+
it.each(['string', '', '22', 'null', '[Object object]'])('Valid for value: %s', function (value) {
|
4
|
+
expect(isString()(value)).toBe(undefined);
|
5
|
+
});
|
6
|
+
it.each([0, 22, null, {}, undefined, []])('Invalid for value: %s', function (value) {
|
7
|
+
expect(isString()(value)).toBe(STRING_RULE_MESSAGE);
|
8
|
+
});
|
9
|
+
it('Можно прокинуть кастомный текст ошибки', function () {
|
10
|
+
var errorMessage = 'test';
|
11
|
+
expect(isString(errorMessage)(22)).toBe(errorMessage);
|
12
|
+
});
|
13
|
+
});
|
package/esm/types.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export declare type Rule<Args extends unknown[]> = (...args: Args) => (value?: unknown) => string | undefined;
|
package/esm/types.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './createRule';
|
package/index.js
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./createRule"), exports);
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isString';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./isString"), exports);
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export declare const STRING_RULE_MESSAGE = "\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u043E\u0439";
|
2
|
+
/**
|
3
|
+
* @example isString('Не строка')('string')
|
4
|
+
* @description Правило проверки на строку.
|
5
|
+
*/
|
6
|
+
export declare const isString: import("../types").Rule<[message?: string | undefined]>;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isString = exports.STRING_RULE_MESSAGE = void 0;
|
4
|
+
var createRule_1 = require("../createRule");
|
5
|
+
exports.STRING_RULE_MESSAGE = 'Должно быть строкой';
|
6
|
+
/**
|
7
|
+
* @example isString('Не строка')('string')
|
8
|
+
* @description Правило проверки на строку.
|
9
|
+
*/
|
10
|
+
exports.isString = (0, createRule_1.createRule)(function (message) {
|
11
|
+
if (message === void 0) { message = exports.STRING_RULE_MESSAGE; }
|
12
|
+
return function (value) {
|
13
|
+
return typeof value === 'string' ? undefined : message;
|
14
|
+
};
|
15
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
var isString_1 = require("./isString");
|
4
|
+
describe('isString', function () {
|
5
|
+
it.each(['string', '', '22', 'null', '[Object object]'])('Valid for value: %s', function (value) {
|
6
|
+
expect((0, isString_1.isString)()(value)).toBe(undefined);
|
7
|
+
});
|
8
|
+
it.each([0, 22, null, {}, undefined, []])('Invalid for value: %s', function (value) {
|
9
|
+
expect((0, isString_1.isString)()(value)).toBe(isString_1.STRING_RULE_MESSAGE);
|
10
|
+
});
|
11
|
+
it('Можно прокинуть кастомный текст ошибки', function () {
|
12
|
+
var errorMessage = 'test';
|
13
|
+
expect((0, isString_1.isString)(errorMessage)(22)).toBe(errorMessage);
|
14
|
+
});
|
15
|
+
});
|
package/package.json
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"name": "@astral/validations",
|
3
|
+
"browser": "./src/index.ts",
|
4
|
+
"main": "./index.js",
|
5
|
+
"version": "0.1.0",
|
6
|
+
"dependencies": {
|
7
|
+
"lodash-es": "^4.17.21"
|
8
|
+
},
|
9
|
+
"author": "Astral.Soft",
|
10
|
+
"license": "MIT",
|
11
|
+
"repository": {
|
12
|
+
"type": "git",
|
13
|
+
"url": "git+https://github.com/kaluga-astral/frontend"
|
14
|
+
},
|
15
|
+
"bugs": {
|
16
|
+
"url": "https://github.com/kaluga-astral/frontend/issues"
|
17
|
+
},
|
18
|
+
"keywords": [],
|
19
|
+
"sideEffects": false,
|
20
|
+
"types": "./esm/index.d.ts",
|
21
|
+
"module": "./esm/index.js"
|
22
|
+
}
|
package/types.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export declare type Rule<Args extends unknown[]> = (...args: Args) => (value?: unknown) => string | undefined;
|
package/types.js
ADDED