{"id":16795831,"url":"https://github.com/mrvautin/parsa","last_synced_at":"2025-03-17T03:15:19.405Z","repository":{"id":57145677,"uuid":"102650776","full_name":"mrvautin/parsa","owner":"mrvautin","description":"Parsa ya data! An all purpose module to parse, sanitize, extract and validate data.","archived":false,"fork":false,"pushed_at":"2017-09-16T17:30:14.000Z","size":68,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-29T04:03:25.387Z","etag":null,"topics":["date","extract","format","isarray","isobject","parse","parse-dates","parsequery","parseurl","phone-number","regex","validate"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/parsa","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/mrvautin.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":"2017-09-06T19:40:26.000Z","updated_at":"2022-12-05T00:00:56.000Z","dependencies_parsed_at":"2022-09-05T13:00:48.096Z","dependency_job_id":null,"html_url":"https://github.com/mrvautin/parsa","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrvautin%2Fparsa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrvautin%2Fparsa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrvautin%2Fparsa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrvautin%2Fparsa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrvautin","download_url":"https://codeload.github.com/mrvautin/parsa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243965779,"owners_count":20375919,"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":["date","extract","format","isarray","isobject","parse","parse-dates","parsequery","parseurl","phone-number","regex","validate"],"created_at":"2024-10-13T09:17:32.296Z","updated_at":"2025-03-17T03:15:19.383Z","avatar_url":"https://github.com/mrvautin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parsa\n\n`parsa` is an all purpose module which can parse, validate, extract and more!\n\n- Parse a date string (with known [format](#parsedate)) into a Javascript Date Object\n- Validate an Object against a schema, including: required, min/max length, numerical, string, array and many [more](#validateobject)\n- Validates IPv4 and IPv6 (true/false)\n- Parses a URL query string into an Object\n- Parses a URL into an Object with Host, Path, Hash, Protocol etc\n- Validates whether a string URL is valid\n- Validates Email address (true/false)\n- Extracts numbers and decimals from string\n- Extracts words from string\n- Extracts phone numbers from string\n- Removes Alpha characters from string\n- Removes numeric characters from string\n- Changes first character of each word to uppercase\n- Checks for a secure password (8 Characters, uppercase, lowercase, number \u0026 special characters)\n- Many many more...\n\n#### Jump to section\n\n- [parseDate](#parsedate)\n- [validateIp](#validateip)\n- [validateIpv6](#validateipv6)\n- [parseQuery](#parsequery)\n- [parseUrl](#parseurl)\n- [validateUrl](#validateurl)\n- [validateEmail](#validateemail)\n- [extractNum](#extractnum)\n- [extractWords](#extractwords)\n- [extractPhone](#extractphone)\n- [securePassword](#securepassword)\n- [removeAlpha](#removealpha)\n- [removeNumeric](#removenumeric)\n- [firstUppercase](#firstuppercase)\n- [validateObject](#validateobject)\n- [isAlpha](#isalpha)\n- [isNumeric](#isnumeric)\n- [isObject](#isobject)\n- [isArray](#isarray)\n- [isString](#isstring)\n- [isFunction](#isfunction)\n- [minLength](#minlength)\n- [maxLength](#maxlength)\n- [isBetweenLength](#isbetweenlength)\n\n`parsa` is only 8KB compare to `Moment.js` which is ~51KB. This is handy if using in the browser.\n\n## Installation\n\n#### Browser\n\n``` html\n\u003cscript type=\"text/javascript\" src=\"dist/parsa.min.js\" charset=\"utf-8\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    console.log('parseDate: 20121125 = ', parsa.parseDate('20121125', 'YYYYMMDD'));\n\u003c/script\u003e\n```\n\n##### CDN\n``` html\n\u003cscript type=\"text/javascript\" src=\"https://cdn.rawgit.com/mrvautin/parsa/dist/parsa.min.js\" charset=\"utf-8\"\u003e\u003c/script\u003e\n```\n\n#### Node\n\n``` javascript\nconst parsa = require('parsa');\nparsa.parseDate('20121125', 'YYYYMMDD');\n```\n\n## Tests\n\n``` shell\nnpm test\n```\n\n## Build\n\n``` shell\ngulp deploy\n```\n\n## parseDate\n\n\nThe `parseDate` function takes a date string and format string parameters and returns a Javascript `Date()` Object.\n\n#### Usage\n\n``` javascript\nparsa.parseDate('20121125', 'YYYYMMDD')\n```\n\n**Returns:**\n\n`Sun Nov 25 2012 01:00:00 GMT+0100 (CET)`\n\n\n\n#### Supported formats\n\n- `YYYYMMDD`\r\n- `YYYYDDMM`\r\n- `DDMMYYYY`\r\n- `MMDDYYYY`\r\n- `MMDDYY`\r\n- `DDMMYY`\r\n- `MM/DD/YYYY`\r\n- `DD/MM/YYYY`\r\n- `YYYY/DD/MM`\r\n- `DD-MM-YYYY`\r\n- `MM-DD-YYYY`\r\n- `YYYY-DD-MM`\r\n- `YYYY-MM-DD`\r\n- `DD MM YYYY`\r\n- `MM DD YYYY`\r\n- `YYYY MM DD`\r\n- `YYYYMMDD HH:MM`\r\n- `YYYYDDMM HH:MM`\r\n- `YYYYMMDD HH:MM:SS`\r\n- `YYYYDDMM HH:MM:SS`\r\n- `YYYY-DD-MM HH:MM`\r\n- `YYYY-MM-DD HH:MM`\r\n- `YYYY/MM/DD HH:MM`\r\n- `YYYY/DD/MM HH:MM`\r\n- `Do MMMM YYYY`\r\n- `Do, MMMM, YYYY`\r\n- `MM MMMM YYYY`\r\n\n\n## validateIp\n\nThe `validateIp` function takes an IP address string and returns a `boolean` value whether it is valid or invalid.\n\n#### Usage\n\n``` javascript\nparsa.validateIp('115.42.150.37')\n```\n\n**Returns:**\n\n`true`\n\n\n\n## validateIpv6\n\nThe `validateIpv6` function takes an IP address string and returns a `boolean` value whether it is valid or invalid.\n\n#### Usage\n\n``` javascript\nparsa.validateIpv6('2001:db8:3:4::')\n```\n\n**Returns:**\n\n`true`\n\n\n\n## parseQuery\n\nThe `parseQuery` function takes a URL and returns an `Object` of the Query string parameters.\n\n#### Usage\n\n``` javascript\nparsa.parseQuery('http://example.com/product.php?category=4\u0026product_id=2140\u0026query=lcd+tv')\n```\n\n**Returns:**\n``` json\n{\n    \"category\": \"4\",\n    \"product_id\": \"2140\",\n    \"query\": \"lcd+tv\"\n}\n```\n\n\n\n## parseUrl\n\nThe `parseUrl` function takes a URL and returns an `Object` of the URL section.\n\n#### Usage\n\n``` javascript\nparsa.parseQuery('https://www.google.com:80/dir/1/2/search.html?arg=0-a\u0026arg1=1-b\u0026arg3-c#hash')\n```\n\n**Returns:**\n``` json\n{\n    \"url\": \"https://www.google.com:80/dir/1/2/search.html?arg=0-a\u0026arg1=1-b\u0026arg3-c#hash\",\n    \"protocol\": \"https\",\n    \"host\": \"www.google.com\",\n    \"port\": \":80\",\n    \"path\": \"/dir/1/2/\",\n    \"file\": \"search.html\",\n    \"query\": \"?arg=0-a\u0026arg1=1-b\u0026arg3-c\",\n    \"hash\": \"#hash\"\n}\n```\n\n\n\n## validateUrl\n\nThe `validateUrl` function takes a URL and returns a `boolean` result.\n\n#### Usage\n\n``` javascript\nparsa.validateUrl('https://www.google.com')\n```\n\n**Returns:**\n`true`\n\n\n\n## validateEmail\n\nThe `validateEmail` function takes a email address string and returns a `boolean` value whether it is valid or invalid.\n\n#### Usage\n\n``` javascript\nparsa.validateEmail('hi@gmail.com')\n```\n\n**Returns:**\n\n`true`\n\n\n\n## extractNum\n\nThe `extractNum` function takes a string and returns an `array` of numbers/decimals found in that string.\n\n#### Usage\n\n``` javascript\nparsa.extractNum('This is a10 string with3.14decimals6 and numbers.')\n```\n\n**Returns:**\n\n``` javascript\n[\n    '10',\n    '3.14',\n    '6'\n]\n```\n\n\n\n## extractWords\n\nThe `extractWords` function takes a string and an `array` of words and returns an `array` of matched words in the string.\n\n#### Usage\n\n``` javascript\nvar words = ['this', 'some', 'words'];\nparsa.extractWords('thisadkfdlfkdisdsstringdfjdkwithdkfdfkldsomefdfdfkdflkwordsjfgjkfg', words)\n```\n\n**Returns:**\n\n``` javascript\n[\n    'this',\n    'some',\n    'words'\n]\n```\n\n\n\n## extractPhone\n\nThe `extractPhone` function takes a string and returns an `array` of matched phone numbers.\n\n#### Usage\n\n``` javascript\nparsa.extractPhone('thisadkfdlfkdisdsstringdfjdkwithdkfdfkldsomefdfdfkdflkwordsjfgjkfg', words)\n```\n\n**Returns:**\n\n``` javascript\n[\n    'this',\n    'some',\n    'words'\n]\n```\n\n\n\n## securePassword\n\nThe `securePassword` function takes a password string returns a `boolean` whether it's a secure password.\n\n#### Usage\n\n``` javascript\nparsa.securePassword('Testing193!')\n```\n\nPassword requirements are set to standard defaults:\n\n- at least 8 characters\n- must contain at least 1 uppercase letter, 1 lowercase letter, and 1 number\n- Can contain special characters\n\n**Returns:**\n\n`true`\n\n\n\n## removeAlpha\n\nThe `removeAlpha` function takes a string and removes all non number characters.\n\n#### Usage\n\n``` javascript\nparsa.removeAlpha('some1number')\n```\n\n**Returns:**\n\n`1`\n\n\n\n## removeNumeric\n\nThe `removeNumeric` function takes a string and removes all numbers.\n\n#### Usage\n\n``` javascript\nparsa.removeNumeric('some1number')\n```\n\n**Returns:**\n\n`somenumber`\n\n\n\n## firstUppercase\n\nThe `firstUppercase` function takes a string and makes the first character of each word uppercase.\n\n#### Usage\n\n``` javascript\nparsa.firstUppercase('this is a test string')\n```\n\n**Returns:**\n\n`This Is A Test String`\n\n\n\n## validateObject\n\nThe `validateObject` function takes an Object and a Schema and returns a validation result with any errors.\n\nEach schema validation requires a `name` and a `rules` array. The `name` property refers to the key in the `Object` being supplied.\n\n#### Supported schema rules\n\n- `isAlpha`\r\n- `isNumeric`\r\n- `isString`\r\n- `minLength`\r\n- `maxLength`\r\n- `isBetweenLength`\r\n- `isObject`\r\n- `isArray`\r\n- `isRequired`\r\n- `securePassword`\r\n\n\n#### Usage\n\n``` javascript\nlet object = {\n    \"test_number\": 1234,\n    \"test_string\": 'abcdefg',\n    \"test_array\": [1, 2, 3],\n    \"test_required\": '',\n    \"test_length\": 'I am a long string'\n};\n\nlet schema = [\n    {\n        \"name\": \"test_number\",\n        \"rules\": [\n            'isNumeric'\n        ]\n    },\n    {\n        \"name\": \"test_string\",\n        \"rules\": [\n            'isString',\n        ]\n    },\n    {\n        \"name\": \"test_array\",\n        \"rules\": [\n            'isArray'\n        ]\n    },\n    {\n        \"name\": \"test_required\",\n        \"rules\": [\n            'isRequired'\n        ]\n    },\n    {\n        \"name\": \"test_length\",\n        \"rules\": [\n            'minLength|5',\n            'maxLength|25'\n        ]\n    }\n];\n```\n\n\u003e Note: when using a schema validation which requires multiple arguments other than the value (Eg: `minLength`, `isBetweenLength` etc) you pass arguments using the `|` character as a separator. For example:\n`isBetweenLength` would look like:\n`isBetweenLength|0|16` which would validate values between 0 and 16 characters in length.\n\n``` javascript\nparsa.validateObject(schema, object)\n```\n\n**Returns:**\n\nWith errors\n``` javascript\n{\n    errors: [\n        {\n            property: 'test_string',\n            message: 'Value is greater than the maximum length'\n        },\n        {\n            property: 'test_required',\n            message: 'Value is required'\n        }\n    ],\n    result: false\n}\n```\n\nWithout errors\n``` javascript\n{\n    errors: [],\n    result: true\n}\n```\n\n\n\n## isAlpha\n\nThe `isAlpha` function takes a value and returns a `boolean` whether it contains only alpha characters.\n\n#### Usage\n\n``` javascript\nparsa.isAlpha('this is a test string')\n```\n\n**Returns:**\n\n`true`\n\n\n\n## isNumeric\n\nThe `isNumeric` function takes value and returns a `boolean` whether it contains only alpha numbers.\n\n#### Usage\n\n``` javascript\nparsa.isNumeric(1234)\n```\n\n**Returns:**\n\n`true`\n\n\n\n## isObject\n\nThe `isObject` function takes value and returns a `boolean` whether it is a `Object`.\n\n#### Usage\n\n``` javascript\nparsa.isObject({\"test\": \"Object\"})\n```\n\n**Returns:**\n\n`true`\n\n\n\n## isArray\n\nThe `isArray` function takes value and returns a `boolean` whether it is a `Array`.\n\n#### Usage\n\n``` javascript\nparsa.isArray(['abcd', '1234'])\n```\n\n**Returns:**\n\n`true`\n\n\n\n## isString\n\nThe `isString` function takes value and returns a `boolean` whether it is a `String`.\n\n#### Usage\n\n``` javascript\nparsa.isString('fkdlfkdl3233')\n```\n\n**Returns:**\n\n`true`\n\n\n\n## isDefined\n\nThe `isDefined` function takes value and returns a `boolean` whether the value is null or undefined.\n\n#### Usage\n\n``` javascript\nparsa.isDefined('')\n```\n\n**Returns:**\n\n`false`\n\n\n\n## isFunction\n\nThe `isFunction` function takes value and returns a `boolean` whether it is a `Function`.\n\n#### Usage\n\n``` javascript\nparsa.isFunction(function test(){})\n```\n\n**Returns:**\n\n`true`\n\n## minLength\n\nThe `minLength` function takes value and a desired length and returns a `boolean` whether it's is greater than supplied value.\n\n#### Usage\n\n``` javascript\nparsa.minLength('23434fdfdfd', 5)\n```\n\n**Returns:**\n\n`true`\n\n## maxLength\n\nThe `maxLength` function takes value and a desired length and returns a `boolean` whether it's is less than supplied value.\n\n#### Usage\n\n``` javascript\nparsa.maxLength('23434fdfdfd', 5)\n```\n\n**Returns:**\n\n`false`\n\n## isBetweenLength\n\nThe `isBetweenLength` function takes value, a min length and a max length and returns a `boolean` whether the value is between the range.\n\n#### Usage\n\n``` javascript\nparsa.maxLength('23434fdf', 5, 10)\n```\n\n**Returns:**\n\n`true`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrvautin%2Fparsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrvautin%2Fparsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrvautin%2Fparsa/lists"}