{"id":21158231,"url":"https://github.com/simbo/validate-by-shorthand","last_synced_at":"2025-03-14T15:27:07.814Z","repository":{"id":57390163,"uuid":"42409940","full_name":"simbo/validate-by-shorthand","owner":"simbo","description":"This library offers a wide range of validation tests, easily accessible via shorthands.","archived":false,"fork":false,"pushed_at":"2015-09-13T20:11:14.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-12T05:33:04.919Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simbo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-13T19:36:22.000Z","updated_at":"2015-09-14T07:14:12.000Z","dependencies_parsed_at":"2022-09-19T04:02:20.003Z","dependency_job_id":null,"html_url":"https://github.com/simbo/validate-by-shorthand","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbo%2Fvalidate-by-shorthand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbo%2Fvalidate-by-shorthand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbo%2Fvalidate-by-shorthand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbo%2Fvalidate-by-shorthand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simbo","download_url":"https://codeload.github.com/simbo/validate-by-shorthand/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243599788,"owners_count":20317162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T12:18:54.415Z","updated_at":"2025-03-14T15:27:07.796Z","avatar_url":"https://github.com/simbo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"validate-by-shorthand\n=====================\n\n  \u003e This library offers a wide range of validation tests, easily accessible \n  \u003e via shorthands.\n\n[![npm Package Version](https://img.shields.io/npm/v/validate-by-shorthand.svg?style=flat-square)](https://www.npmjs.com/package/validate-by-shorthand)\n[![MIT License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://simbo.mit-license.org)\n[![Travis Build Status](https://img.shields.io/travis/simbo/validate-by-shorthand/master.svg?style=flat-square)](https://travis-ci.org/simbo/validate-by-shorthand)\n\n[![Dependencies Status](https://img.shields.io/david/simbo/validate-by-shorthand.svg?style=flat-square)](https://david-dm.org/simbo/validate-by-shorthand)\n[![devDependencies Status](https://img.shields.io/david/dev/simbo/validate-by-shorthand.svg?style=flat-square)](https://david-dm.org/simbo/validate-by-shorthand#info=devDependencies)\n[![Code Climate GPA](https://img.shields.io/codeclimate/github/simbo/validate-by-shorthand.svg?style=flat-square)](https://codeclimate.com/github/simbo/validate-by-shorthand)\n[![Code Climate Test Coverage](https://img.shields.io/codeclimate/coverage/github/simbo/validate-by-shorthand.svg?style=flat-square)](https://codeclimate.com/github/simbo/validate-by-shorthand)\n\n---\n\n\n## Usage\n\n``` javascript\nvar validate = require('validate-by-shorthand');\n\n// validate using shorthands\nvalidate('string!empty', 'foo'); // true\nvalidate('string!empty', ''); // false\nvalidate('number\u003e0', 5); // true\nvalidate('number\u003e0', 0); // false\nvalidate('string[]', ['foo', '', 'bar']); // true\nvalidate('string[]', ['foo', '', 5]); // false\n\n// validate using regular expressions\nvalidate(/^[A-Z]+$/, 'ABC'); // true\nvalidate(/^[A-Z]+$/, 'abc'); // false\n\n// validate using functions\nvar test = function(v) {\n    return [1,2,3].indexOf(v) !== -1;\n};\nvalidate(test, 2); // true\nvalidate(test, 5); // false\n\n// validate using an array of shorthands, regexps and/or functions\n// returning true if any test succeeds\nvar arr = ['number\u003c0', test, /^[A-Z]$/];\nvalidate(arr, -2); // true\nvalidate(arr, 0); // false\nvalidate(arr, 2); // true\nvalidate(arr, 5); // false\nvalidate(arr, 'A'); // true\nvalidate(arr, 'a'); // true\n```\n\n\n## Shorthands\n\ntype tests supported by [`util.is*`](https://nodejs.org/api/util.html) functions:\n  - `array`\n  - `boolean`\n  - `null`\n  - `nullorundefined`\n  - `number`\n  - `string`\n  - `symbol`\n  - `undefined`\n  - `regexp`\n  - `object`\n  - `date`\n  - `error`\n  - `function`\n  - `primitive`\n  - `buffer`\n\nreturn true for anything\n  - `any`  \n\nnon-empty of respective type\n  - `string!empty`  \n  - `array!empty`  \n  - `object!empty`  \n\nnumber tests\n  - `number\u003e0`\n  - `number\u003e=0`\n  - `number\u003c0`\n  - `number\u003c=0`\n  - `integer`\n  - `float`\n\ntests for an array with elements of respective type:\n  - `array[]`\n  - `boolean[]`\n  - `number[]`\n  - `string[]`\n  - `symbol[]`\n  - `regexp[]`\n  - `object[]`\n  - `date[]`\n  - `error[]`\n  - `function[]`\n  - `primitive[]`\n  - `buffer[]`\n  - `string!empty[]`\n  - `array!empty[]`\n  - `object!empty[]`\n  - `number\u003e0[]`\n  - `number\u003e=0[]`\n  - `number\u003c0[]`\n  - `number\u003c=0[]`\n  - `integer[]`\n  - `float[]`\n\ntest for an object with properties of an respective type:\n  - `array{}`\n  - `boolean{}`\n  - `number{}`\n  - `string{}`\n  - `symbol{}`\n  - `regexp{}`\n  - `object{}`\n  - `date{}`\n  - `error{}`\n  - `function{}`\n  - `primitive{}`\n  - `buffer{}`\n  - `string!empty{}`\n  - `array!empty{}`\n  - `object!empty{}`\n  - `number\u003e0{}`\n  - `number\u003e=0{}`\n  - `number\u003c0{}`\n  - `number\u003c=0{}`\n  - `integer{}`\n  - `float{}`\n\n\n## License\n\n[MIT \u0026copy; 2015 Simon Lepel](http://simbo.mit-license.org/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimbo%2Fvalidate-by-shorthand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimbo%2Fvalidate-by-shorthand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimbo%2Fvalidate-by-shorthand/lists"}