Comparing version 0.0.1 to 0.1.0
@@ -5,4 +5,6 @@ 'use strict'; | ||
var moo = require('moo'); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var moo = _interopDefault(require('moo')); | ||
function minify(query) { | ||
@@ -9,0 +11,0 @@ const lexer = moo.states({ |
@@ -1,4 +0,4 @@ | ||
import { states } from 'moo'; | ||
import moo from 'moo'; | ||
export default function minify(query) { | ||
const lexer = states({ | ||
const lexer = moo.states({ | ||
main: { | ||
@@ -5,0 +5,0 @@ comment: /#.*$/, |
@@ -1,1 +0,1 @@ | ||
import{states}from"moo";function minify(t){const e=states({main:{comment:/#.*$/,blockString:{match:/:\s*"""/,push:"blockString"},description:{match:'"""',push:"description"},string:/"(?:\\"|[^"])*"/,variable:/\$[A-z\d]+/,id:/[A-z\d]+/,ws:{match:/[\s\t]+/,lineBreaks:true},any:/./},description:{descriptionEnd:{match:'"""',pop:1},ws:{match:/[\s\t]+/,lineBreaks:true},description:/./},blockString:{esc:{match:'"""',pop:1},stringSpace:{match:/[\s\t]+/,lineBreaks:true},any:/./}});e.reset(t);let i="";for(const{type:t,value:r}of e){if(t!=="comment"&&t!=="description"&&t!=="descriptionEnd"){i+=r}}e.reset(i);const r=Array.from(e);return r.map(({type:t,value:e},i)=>{if(t==="blockString"){return e.replace(/\s*/g,"")}if(t==="ws"){return r[i-1]&&r[i-1].type==="id"&&r[i+1]&&r[i+1].type==="id"?" ":""}return e}).join("").trim()}export default minify; | ||
import moo from"moo";function minify(t){const e=moo.states({main:{comment:/#.*$/,blockString:{match:/:\s*"""/,push:"blockString"},description:{match:'"""',push:"description"},string:/"(?:\\"|[^"])*"/,variable:/\$[A-z\d]+/,id:/[A-z\d]+/,ws:{match:/[\s\t]+/,lineBreaks:true},any:/./},description:{descriptionEnd:{match:'"""',pop:1},ws:{match:/[\s\t]+/,lineBreaks:true},description:/./},blockString:{esc:{match:'"""',pop:1},stringSpace:{match:/[\s\t]+/,lineBreaks:true},any:/./}});e.reset(t);let i="";for(const{type:t,value:r}of e){if(t!=="comment"&&t!=="description"&&t!=="descriptionEnd"){i+=r}}e.reset(i);const r=Array.from(e);return r.map(({type:t,value:e},i)=>{if(t==="blockString"){return e.replace(/\s*/g,"")}if(t==="ws"){return r[i-1]&&r[i-1].type==="id"&&r[i+1]&&r[i+1].type==="id"?" ":""}return e}).join("").trim()}export default minify; |
{ | ||
"name": "gqlmin", | ||
"description": "4 kB (gzip) GraphQL query minifier", | ||
"version": "0.0.1", | ||
"description": "< 1 kB GraphQL query minifier", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
@@ -34,3 +34,3 @@ "bin": { | ||
"dependencies": { | ||
"@types/moo": "^0.5.1", | ||
"@types/moo": "^0.5.3", | ||
"moo": "^0.5.1" | ||
@@ -40,21 +40,21 @@ }, | ||
"@pika/pack": "^0.5.0", | ||
"@pika/plugin-build-node": "^0.8.1", | ||
"@pika/plugin-build-web": "^0.8.1", | ||
"@pika/plugin-copy-assets": "^0.8.1", | ||
"@pika/plugin-ts-standard-pkg": "^0.8.1", | ||
"@types/jest": "^24.9.0", | ||
"@typescript-eslint/eslint-plugin": "^2.17.0", | ||
"@typescript-eslint/parser": "^2.17.0", | ||
"chalk": "^3.0.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.9.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"fs-extra": "^8.1.0", | ||
"jest": "^24.9.0", | ||
"meow": "^6.0.0", | ||
"@pika/plugin-build-node": "^0.9.2", | ||
"@pika/plugin-build-web": "^0.9.2", | ||
"@pika/plugin-copy-assets": "^0.9.2", | ||
"@pika/plugin-ts-standard-pkg": "^0.9.2", | ||
"@types/jest": "^25.2.2", | ||
"@typescript-eslint/eslint-plugin": "^2.33.0", | ||
"@typescript-eslint/parser": "^2.33.0", | ||
"chalk": "^4.0.0", | ||
"eslint": "^7.0.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"fs-extra": "^9.0.0", | ||
"jest": "^26.0.1", | ||
"meow": "^7.0.1", | ||
"pika-plugin-unpkg-field": "^1.1.0", | ||
"prettier": "^1.19.1", | ||
"terser": "^4.6.3", | ||
"ts-jest": "^24.3.0", | ||
"typescript": "^3.7.5" | ||
"prettier": "^2.0.5", | ||
"terser": "^4.6.13", | ||
"ts-jest": "^26.0.0", | ||
"typescript": "^3.9.2" | ||
}, | ||
@@ -61,0 +61,0 @@ "source": "dist-src/index.js", |
@@ -0,11 +1,11 @@ | ||
[![version (scoped)](https://img.shields.io/npm/v/gqlmin.svg)](https://www.npmjs.com/package/gqlmin) | ||
[![minzip](https://badgen.net/bundlephobia/minzip/gqlmin)](https://bundlephobia.com/gqlmin) | ||
[![codecov](https://codecov.io/gh/dangodev/gqlmin/branch/master/graph/badge.svg)](https://codecov.io/gh/dangodev/gqlmin) | ||
# 🗜 gqlmin | ||
4 kB (gzip) GraphQL query minifier. | ||
`< 1 kB` GraphQL query minifier (`3.4 kB` (gzip) if you include its only dependency, [Moo][moo]). | ||
This library removes all insignificant whitespace within a GraphQL query, as well as comments. | ||
The actual library itself is `843 bytes`; the `4 kB` includes [Moo][moo], the lexer it uses. | ||
### | ||
## Usage | ||
@@ -40,2 +40,5 @@ | ||
_Note: for Node.js < 13.3.0 or if ES Modules aren’t supported, use | ||
`const gqlmin = require('gqlmin')` instead._ | ||
### CLI | ||
@@ -42,0 +45,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
19312
179
76
Updated@types/moo@^0.5.3