This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
<a name="2.0.2"></a>
## [2.0.2](https://github.com/poppinss/haye/compare/v2.0.1...v2.0.2) (2018-06-18)
<a name="2.0.1"></a>
## [2.0.1](https://github.com/poppinss/haye/compare/v2.0.0...v2.0.1) (2017-12-08)
<a name="2.0.0"></a>
# [2.0.0](https://github.com/poppinss/haye/compare/v1.0.1...v2.0.0) (2017-12-01)
### Features
* rewrite ([d825339](https://github.com/poppinss/haye/commit/d825339))
<a name="1.0.1"></a>
## [1.0.1](https://github.com/poppinss/haye/compare/v1.0.0...v1.0.1) (2016-09-30)
<a name="1.0.0"></a>
# 1.0.0 (2016-09-30)
### Features
* initial commit ([8568757](https://github.com/poppinss/haye/commit/8568757))
+174
View File
@@ -0,0 +1,174 @@
# Haye
Haye is a simple super fast string expression parser. In support `pipe` and `qs` string expressions ( explained below ).
> **Limitations**
The keys/values inside the expression cannot have any of the reserved keywords, otherwise parser will mis-behave.
---
<details>
<summary> Benchmarks </summary>
<pre>
<code>
haye #pipeToArray x 741,030 ops/sec ±0.97% (90 runs sampled)
haye #pipeToJson x 313,101 ops/sec ±0.95% (87 runs sampled)
haye #qsToArray x 698,688 ops/sec ±0.74% (91 runs sampled)
haye #qsToJson x 303,482 ops/sec ±1.10% (89 runs sampled)
</code>
</pre>
</details>
<details>
<summary> Comparison with 1.0.1 </summary>
<h4> Legacy </h4>
<pre>
<code>
219,138 op/s » haye #pipeToArray #legacy
170,068 op/s » haye #pipeToJson #legacy
147,594 op/s » haye #qsToArray #legacy
121,094 op/s » haye #qsToJson #legacy
</code>
</pre>
<h4> Latest </h4>
<pre>
<code>
747,298 op/s » haye #pipeToArray
363,152 op/s » haye #pipeToJson
742,310 op/s » haye #qsToArray
349,075 op/s » haye #qsToJson
</code>
</pre>
</details>
<details>
<summary> Upgrading from 1.0.1 </summary>
<p> There are couple of breaking changes from 1.0.1 to 2.x.x </p>
<ol>
<li>
All methods to convert <code>Arrays</code> and <code>Objects</code> have been removed.
</li>
<li>
The `args` property in `toArray` methods is always an array. Earlier it used to be string for single values and array for multiple.
</li>
<li>
The value in `key/value` pair is always an array. Earlier it used to be string for single values and array for multiple.
</li>
</ol>
</details>
### Pipe expression
The pipe based expression is very popular in Laravel community, due to their [Validation engine](https://laravel.com/docs/validation), and same is adopted by [Indicative](http://indicative.adonisjs.com).
#### Syntax example:
```js
required|email|max:4|range:10,30
```
1. Each item is separated by `|`
2. The values are defined after `:`
3. Multiple values are separated by `,`.
4. White spaces in keys are trimmed.
---
### Qs expression
The query string expression is almost similar to the URL query string, with couple of small modifications to make the expression readable.
#### Syntax example:
```
required,email,max=4,range=[1, 10]
```
1. Each item is separated by `,`
2. The values are defined after `=`
3. Multiple values are separated by `,` inside `[]`.
4. White spaces in keys are trimmed.
## Installation
The module is available on npm
```bash
npm i haye
# yarn
yarn add haye
```
## Usage
Below is the bunch of usage examples
#### Pipe -> Array
```js
const haye = require('haye')
const expression = 'required|email:unique,users'
const parsed = haye.fromPipe(expression).toArray()
```
Output
```js
[
{ name: 'required', args: [] },
{ name: 'email', args: ['unique', 'users'] }
]
```
#### Pipe -> JSON
```js
const haye = require('haye')
const expression = 'required|email:unique,users'
const parsed = haye.fromPipe(expression).toJSON()
```
Output
```js
{
required: [],
email: [ 'unique', 'users' ]
}
```
#### Qs -> Array
```js
const haye = require('haye')
const expression = 'required,email=[unique,users]'
const parsed = haye.fromQS(expression).toArray()
```
Output
```js
[
{ name: 'required', args: [] },
{ name: 'email', args: ['unique', 'users'] }
]
```
#### Qs -> JSON
```js
const haye = require('haye')
const expression = 'required,email=[unique,users]'
const parsed = haye.fromQS(expression).toJSON()
```
Output
```js
{
required: [],
email: [ 'unique', 'users' ]
}
```
+1
View File
@@ -0,0 +1 @@
function n(){return{nodes:[],currentNode:null,add:function(){this.currentNode={name:"",args:[]},this.nodes.push(this.currentNode)},appendKey:function(n,e){32!==e&&(this.currentNode.name+=n)},appendValue:function(n){this.currentNode.args[this.currentNode.args.length-1]+=n},shiftValue:function(){this.currentNode.args.push("")},toJSON:function(){return this.nodes}}}export default n;
+1
View File
@@ -0,0 +1 @@
"use strict";module.exports=function(){return{nodes:[],currentNode:null,add:function(){this.currentNode={name:"",args:[]},this.nodes.push(this.currentNode)},appendKey:function(e,n){32!==n&&(this.currentNode.name+=e)},appendValue:function(e){this.currentNode.args[this.currentNode.args.length-1]+=e},shiftValue:function(){this.currentNode.args.push("")},toJSON:function(){return this.nodes}}};
+1
View File
@@ -0,0 +1 @@
function n(){return{nodes:[],currentNode:null,add:function(){this.currentNode={name:"",args:[]},this.nodes.push(this.currentNode)},appendKey:function(n,e){32!==e&&(this.currentNode.name+=n)},appendValue:function(n){this.currentNode.args[this.currentNode.args.length-1]+=n},shiftValue:function(){this.currentNode.args.push("")},toJSON:function(){return this.nodes.reduce((function(n,e){return n[e.name]=e.args,n}),{})}}}export default n;
+1
View File
@@ -0,0 +1 @@
"use strict";module.exports=function(){return{nodes:[],currentNode:null,add:function(){this.currentNode={name:"",args:[]},this.nodes.push(this.currentNode)},appendKey:function(e,n){32!==n&&(this.currentNode.name+=e)},appendValue:function(e){this.currentNode.args[this.currentNode.args.length-1]+=e},shiftValue:function(){this.currentNode.args.push("")},toJSON:function(){return this.nodes.reduce((function(e,n){return e[n.name]=n.args,e}),{})}}};
+1
View File
@@ -0,0 +1 @@
function a(a,e){e.add();for(var r=a.length,d=0,n="name";d<r;){var t=a[d++],o=t.charCodeAt(0);58===o||44===o?(n="arg",e.shiftValue()):124===o?(n="name",e.add()):"arg"===n?e.appendValue(t):e.appendKey(t,o)}return e.toJSON()}export default a;
+1
View File
@@ -0,0 +1 @@
"use strict";module.exports=function(a,e){e.add();for(var r=a.length,t=0,d="name";t<r;){var n=a[t++],o=n.charCodeAt(0);58===o||44===o?(d="arg",e.shiftValue()):124===o?(d="name",e.add()):"arg"===d?e.appendValue(n):e.appendKey(n,o)}return e.toJSON()};
+1
View File
@@ -0,0 +1 @@
function a(a,e){e.add();for(var r=a.length,d=0,n="name",t=!1;d<r;){var o=a[d++],p=o.charCodeAt(0);91===p?t=!0:93===p?t=!1:61===p||44===p&&t?(n="arg",e.shiftValue()):44===p?(n="name",e.add()):"arg"===n?e.appendValue(o):e.appendKey(o,p)}return e.toJSON()}export default a;
+1
View File
@@ -0,0 +1 @@
"use strict";module.exports=function(a,e){e.add();for(var r=a.length,t=0,d="name",n=!1;t<r;){var o=a[t++],u=o.charCodeAt(0);91===u?n=!0:93===u?n=!1:61===u||44===u&&n?(d="arg",e.shiftValue()):44===u?(d="name",e.add()):"arg"===d?e.appendValue(o):e.appendKey(o,u)}return e.toJSON()};
+1
View File
@@ -0,0 +1 @@
function n(n,e){e.add();for(var r=n.length,t=0,u="name";t<r;){var o=n[t++],a=o.charCodeAt(0);58===a||44===a?(u="arg",e.shiftValue()):124===a?(u="name",e.add()):"arg"===u?e.appendValue(o):e.appendKey(o,a)}return e.toJSON()}function e(n,e){e.add();for(var r=n.length,t=0,u="name",o=!1;t<r;){var a=n[t++],d=a.charCodeAt(0);91===d?o=!0:93===d?o=!1:61===d||44===d&&o?(u="arg",e.shiftValue()):44===d?(u="name",e.add()):"arg"===u?e.appendValue(a):e.appendKey(a,d)}return e.toJSON()}function r(){return{nodes:[],currentNode:null,add:function(){this.currentNode={name:"",args:[]},this.nodes.push(this.currentNode)},appendKey:function(n,e){32!==e&&(this.currentNode.name+=n)},appendValue:function(n){this.currentNode.args[this.currentNode.args.length-1]+=n},shiftValue:function(){this.currentNode.args.push("")},toJSON:function(){return this.nodes}}}function t(){return{nodes:[],currentNode:null,add:function(){this.currentNode={name:"",args:[]},this.nodes.push(this.currentNode)},appendKey:function(n,e){32!==e&&(this.currentNode.name+=n)},appendValue:function(n){this.currentNode.args[this.currentNode.args.length-1]+=n},shiftValue:function(){this.currentNode.args.push("")},toJSON:function(){return this.nodes.reduce((function(n,e){return n[e.name]=e.args,n}),{})}}}var u={fromPipe:function(e){return{toArray:function(){return n(e,new r)},toJSON:function(){return n(e,new t)}}},fromQS:function(n){return{toArray:function(){return e(n,new r)},toJSON:function(){return e(n,new t)}}}};export default u;
+1
View File
@@ -0,0 +1 @@
"use strict";function n(n,e){e.add();for(var r=n.length,t=0,u="name";t<r;){var o=n[t++],a=o.charCodeAt(0);58===a||44===a?(u="arg",e.shiftValue()):124===a?(u="name",e.add()):"arg"===u?e.appendValue(o):e.appendKey(o,a)}return e.toJSON()}function e(n,e){e.add();for(var r=n.length,t=0,u="name",o=!1;t<r;){var a=n[t++],d=a.charCodeAt(0);91===d?o=!0:93===d?o=!1:61===d||44===d&&o?(u="arg",e.shiftValue()):44===d?(u="name",e.add()):"arg"===u?e.appendValue(a):e.appendKey(a,d)}return e.toJSON()}function r(){return{nodes:[],currentNode:null,add:function(){this.currentNode={name:"",args:[]},this.nodes.push(this.currentNode)},appendKey:function(n,e){32!==e&&(this.currentNode.name+=n)},appendValue:function(n){this.currentNode.args[this.currentNode.args.length-1]+=n},shiftValue:function(){this.currentNode.args.push("")},toJSON:function(){return this.nodes}}}function t(){return{nodes:[],currentNode:null,add:function(){this.currentNode={name:"",args:[]},this.nodes.push(this.currentNode)},appendKey:function(n,e){32!==e&&(this.currentNode.name+=n)},appendValue:function(n){this.currentNode.args[this.currentNode.args.length-1]+=n},shiftValue:function(){this.currentNode.args.push("")},toJSON:function(){return this.nodes.reduce((function(n,e){return n[e.name]=e.args,n}),{})}}}var u={fromPipe:function(e){return{toArray:function(){return n(e,new r)},toJSON:function(){return n(e,new t)}}},fromQS:function(n){return{toArray:function(){return e(n,new r)},toJSON:function(){return e(n,new t)}}}};module.exports=u;
+56
View File
@@ -0,0 +1,56 @@
{
"name": "haye",
"version": "3.0.0",
"description": "Haye is a super fast string based expression parser for Node.js",
"main": "dist/haye.js",
"module": "dist/haye.es.js",
"browser": "dist/haye.browser.js",
"files": [
"dist"
],
"scripts": {
"prepublishOnly": "npm run build",
"pretest": "npm run lint && npm run build",
"test": "node japaFile.js",
"build": "rollup -c rollup.config.js",
"lint": "standard src/**/*.js index.js test/**/*.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"benchmark": "matcha benchmarks/index.js"
},
"keywords": [
"string-parser",
"indicative",
"expression"
],
"author": "virk",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.13.10",
"@rollup/plugin-babel": "^5.3.0",
"babel-preset-env": "^1.7.0",
"benchmark": "^2.1.4",
"coveralls": "^3.1.0",
"cz-conventional-changelog": "^3.3.0",
"japa": "^3.1.1",
"rollup": "^2.42.2",
"rollup-plugin-terser": "^7.0.2",
"standard": "^16.0.3"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"directories": {
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/poppinss/haye.git"
},
"bugs": {
"url": "https://github.com/poppinss/haye/issues"
},
"homepage": "https://github.com/poppinss/haye#readme"
}