zerde 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{ResultAsync as e,fromThrowable as t}from"neverthrow";import{parse as n}from"jsonc-parser";import{configure as r}from"safe-stable-stringify";const i={allowEmptyContent:!0,allowTrailingComma:!0,disallowComments:!0};function a(e,t={}){let r={...t,...i},a=[],o=n(e,a,r);if(a.length>0)throw SyntaxError(`Could not parse JSON`,{cause:a});return o}const o=0,s=r({bigint:!1,circularValue:SyntaxError,deterministic:!0,strict:!0});function c(e,t){let n=s(e,null,t);if(n===void 0)throw SyntaxError(`safe-stable-stringify should have thrown an error if trying to stringify an invalid json object`);return n}const l=Object.keys,u=Object.entries;var d=class extends Error{constructor(e,t){super(e,{cause:t.cause}),this.name=this.constructor.name}};const f=[`.`,`/`,`\\`,`+`];function p(e){let t=e.trim().toLowerCase();if(!t)return t;let n=t.indexOf(`;`);n>0&&(t=t.slice(0,n));let r=Math.max(...f.map(e=>t.lastIndexOf(e)));return r<0?t:t.slice(r+1)}if(import.meta.vitest){let{describe:e,it:t,expect:n}=import.meta.vitest,r={lowercase:`json`,uppercase:`JSON`,mixedcase:`jSoN`,extension:`.json`,file:`file.json`,"file with path":`some/path/to/file.json`,"file with a windows path":`some\\path\\to\\file.json`,"basic media type":`application/json`,"complex media type":`application/customFormat+json`,"media type with charset":`application/customFormat+json; charset=utf-8`};e(`extractFormatSuffix`,()=>{for(let[e,i]of u(r)){let r=`Can handle ${e}: ${i}`;t(r,()=>{n(p(i)).toEqual(`json`)})}})}var m=class extends d{};const h={json:i},g=t((e,t)=>{let{format:n,...r}=t,i=l(r).sort().at(0)??``,o=p(n??i);return o===`json`?a(e,r.json):e},e=>new m(`Could not parse content`,{cause:e}));function _(e=`Invalid type`){return{type:`string`,message:e,"~standard":{version:1,vendor:`StandardSchema`,validate(t){return typeof t==`string`?{value:t}:{issues:[{message:e}]}}}}}var v=class extends d{};const y={json:o},b=t((e,t)=>{if(typeof e==`string`)return e;let{format:n,...r}=t,i=p(n??``);return c(e,r.json)},e=>new v(`Could not stringify content`,{cause:e}));var x=class extends d{issues;constructor(e){super(`Content was not valid`,{cause:e}),this.issues=e}};const S=e.fromThrowable(async(e,t)=>{let n=await t[`~standard`].validate(e);if(n.issues)throw new x(n.issues);return n.value},e=>e);var C=class{parseOptions=h;stringifyOptions=y;constructor(e={}){this.parseOptions={...e.parse,...h}}parse=(e,t,n)=>{if(typeof e==`string`){let r=typeof n==`string`?{format:n}:n,i={...this.parseOptions,...r};return g(e,i).asyncAndThen(e=>S(e,t))}return S(e,t)};stringify=(e,t,n)=>{let r=typeof n==`string`?{format:n}:n,i={...this.stringifyOptions,...r};return S(e,t).andThen(e=>b(e,i))}};const w=new C,T=w.parse,E=w.stringify;export{d as EnhancedError,m as ParseError,v as StringifyError,x as ValidationError,C as Zerde,h as defaultParseOptions,y as defaultStringifyOptions,u as objectEntries,l as objectKeys,g as parseIt,_ as parseString,b as stringifyIt,S as validateIt,w as zerde,T as zparse,E as zstringify};
1
+ import{ResultAsync as e,fromThrowable as t}from"neverthrow";import{parse as n}from"jsonc-parser";import{configure as r}from"safe-stable-stringify";const i={allowEmptyContent:!0,allowTrailingComma:!0,disallowComments:!0};function a(e,t={}){let r={...t,...i},a=[],o=n(e,a,r);if(a.length>0)throw SyntaxError(`Could not parse JSON`,{cause:a});return o}const o=0,s=r({bigint:!1,circularValue:TypeError,deterministic:!0,strict:!0});function c(e,t){let n=s(e,null,t);if(n===void 0)throw SyntaxError(`safe-stable-stringify should have thrown an error if trying to stringify an invalid json object`);return n}const l=Object.keys,u=Object.entries;var d=class extends Error{constructor(e,t){super(e,{cause:t.cause}),this.name=this.constructor.name}};const f=[`.`,`/`,`\\`,`+`];function p(e){let t=e.trim().toLowerCase();if(!t)return t;let n=t.indexOf(`;`);n>0&&(t=t.slice(0,n));let r=Math.max(...f.map(e=>t.lastIndexOf(e)));return r<0?t:t.slice(r+1)}if(import.meta.vitest){let{describe:e,it:t,expect:n}=import.meta.vitest,r={lowercase:`json`,uppercase:`JSON`,mixedcase:`jSoN`,extension:`.json`,file:`file.json`,"file with path":`some/path/to/file.json`,"file with a windows path":`some\\path\\to\\file.json`,"basic media type":`application/json`,"complex media type":`application/customFormat+json`,"media type with charset":`application/customFormat+json; charset=utf-8`};e(`extractFormatSuffix`,()=>{for(let[e,i]of u(r)){let r=`Can handle ${e}: ${i}`;t(r,()=>{n(p(i)).toEqual(`json`)})}})}var m=class extends d{};const h={json:i},g=t((e,t)=>{let{format:n,...r}=t,i=l(r).sort().at(0)??``,o=p(n??i);return o===`json`?a(e,r.json):e},e=>new m(`Could not parse content`,{cause:e}));function _(e=`Invalid type`){return{type:`string`,message:e,"~standard":{version:1,vendor:`StandardSchema`,validate(t){return typeof t==`string`?{value:t}:{issues:[{message:e}]}}}}}var v=class extends d{};const y={json:o},b=t((e,t)=>{if(typeof e==`string`)return e;let{format:n,...r}=t,i=p(n??``);return c(e,r.json)},e=>new v(`Could not stringify content`,{cause:e}));var x=class extends d{issues;constructor(e){super(`Content was not valid`,{cause:e}),this.issues=e}};const S=e.fromThrowable(async(e,t)=>{let n=await t[`~standard`].validate(e);if(n.issues)throw new x(n.issues);return n.value},e=>e);var C=class{parseOptions=h;stringifyOptions=y;constructor(e={}){this.parseOptions={...e.parse,...h}}parse=(e,t,n)=>{if(typeof e==`string`){let r=typeof n==`string`?{format:n}:n,i={...this.parseOptions,...r};return g(e,i).asyncAndThen(e=>S(e,t))}return S(e,t)};stringify=(e,t,n)=>{let r=typeof n==`string`?{format:n}:n,i={...this.stringifyOptions,...r};return S(e,t).andThen(e=>b(e,i))}};const w=new C,T=w.parse,E=w.stringify;export{d as EnhancedError,m as ParseError,v as StringifyError,x as ValidationError,C as Zerde,h as defaultParseOptions,y as defaultStringifyOptions,u as objectEntries,l as objectKeys,g as parseIt,_ as parseString,b as stringifyIt,S as validateIt,w as zerde,T as zparse,E as zstringify};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zerde",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "parsing, and stringifying combined with schema validation",
5
5
  "keywords": [
6
6
  "parse",