This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## @superset-ui/validator | ||
|
||
[![Version](https://img.shields.io/npm/v/@superset-ui/validator.svg?style=flat)](https://img.shields.io/npm/v/@superset-ui/validator.svg?style=flat) | ||
[![David (path)](https://img.shields.io/david/apache-superset/superset-ui.svg?path=packages%2Fsuperset-ui-validator&style=flat-square)](https://david-dm.org/apache-superset/superset-ui?path=packages/superset-ui-validator) | ||
|
||
Description | ||
|
||
#### Example usage | ||
|
||
```js | ||
import { xxx } from '@superset-ui/validator'; | ||
``` | ||
|
||
#### API | ||
|
||
`fn(args)` | ||
|
||
- Do something | ||
|
||
### Development | ||
|
||
`@data-ui/build-config` is used to manage the build configuration for this package including babel | ||
builds, jest testing, eslint, and prettier. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@superset-ui/validator", | ||
"version": "0.0.0", | ||
"description": "Superset UI validator", | ||
"sideEffects": false, | ||
"main": "lib/index.js", | ||
"module": "esm/index.js", | ||
"files": [ | ||
"esm", | ||
"lib" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/apache-superset/superset-ui.git" | ||
}, | ||
"keywords": ["superset"], | ||
"author": "Superset", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/apache-superset/superset-ui/issues" | ||
}, | ||
"homepage": "https://github.com/apache-superset/superset-ui#readme", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"peerDependencies": { | ||
"@superset-ui/translation": "^0.12.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as validateInteger } from './validateInteger'; | ||
export { default as validateNumber } from './validateNumber'; | ||
export { default as validateNonEmpty } from './validateNonEmpty'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { t } from '@superset-ui/translation'; | ||
|
||
export default function validateInteger(v: unknown) { | ||
if ( | ||
(typeof v === 'string' && Number.isInteger(Number(v))) || | ||
(typeof v === 'number' && Number.isInteger(v)) | ||
) { | ||
return false; | ||
} | ||
|
||
return t('is expected to be an integer'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { t } from '@superset-ui/translation'; | ||
|
||
export default function isNotEmpty(v: unknown) { | ||
if (v === null || typeof v === 'undefined' || v === '' || (Array.isArray(v) && v.length === 0)) { | ||
return t('cannot be empty'); | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { t } from '@superset-ui/translation'; | ||
|
||
export default function validateInteger(v: unknown) { | ||
if ( | ||
(typeof v === 'string' && Number.isFinite(Number(v))) || | ||
(typeof v === 'number' && Number.isFinite(v)) | ||
) { | ||
return false; | ||
} | ||
|
||
return t('is expected to be a number'); | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/superset-ui-validator/test/validateInteger.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { validateInteger } from '../src'; | ||
|
||
describe('validateInteger()', () => { | ||
it('returns the warning message if invalid', () => { | ||
expect(validateInteger(10.1)).toBeTruthy(); | ||
expect(validateInteger(undefined)).toBeTruthy(); | ||
expect(validateInteger(null)).toBeTruthy(); | ||
expect(validateInteger('')).toBeTruthy(); | ||
}); | ||
it('returns false if the input is valid', () => { | ||
expect(validateInteger(10)).toBeFalsy(); | ||
expect(validateInteger('10')).toBeFalsy(); | ||
}); | ||
}); |