-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.min.js
4 lines (4 loc) · 1.1 KB
/
index.min.js
1
2
3
4
function f(e=""){let r={},l="",s=[],t="",a=0,b=0,i=!1,n=!1,u=!1,k="",c="",h=/-|:|\r\n|\n|\r|\s|[^:\s\r\n]+/y;for(;(s=h.exec(e))!==null;){switch(t=s[0],a){case 0:switch(!0){case t==="-":b++,a=1;break;case/^(\s)$/.test(t):a=0;break;default:i=!0;break}break;case 1:switch(!0){case t==="-":b++,a=1;break;case/^(\r\n|\n|\r)$/.test(t):if(b<3)throw Error("ERR: Meta boundary must have at least 3 dashes");n?(u=!0,a=5):(n=!0,a=2),b=0;break;default:break}break;case 2:switch(!0){case t===":":a=3;break;case/^(\s)$/.test(t):a=2;break;case/^(\r\n|\n|\r)$/.test(t):throw Error("ERR: Broken key:value pair");default:k+=t,a=2;break}break;case 3:switch(!0){case(c===""&&/^(\s)$/.test(t)):a=3;break;case/^(\r\n|\n|\r)$/.test(t):a=1,r[k]=c.trimRight(),k="",c="";break;default:a=3,c+=t;break}break}if(i){l=e;break}if(u){l=e.substr(h.lastIndex,e.length-1);break}}return{meta:r,body:l}}function o(e){if(!e.meta||Object.keys(e.meta).length===0)return e.body;let r=`---
`;return Object.keys(e.meta).forEach(s=>{r+=`${s}: ${e.meta[s]}
`}),r+=`---
`,e.body&&(r+=e.body),r}var y={parse:f,stringify:o};export{y as default,f as parse,o as stringify};