Git Product home page Git Product logo

destr's People

Contributors

allenyu0118 avatar atinux avatar chalkygames123 avatar clarkdo avatar divine avatar frencojobs avatar kricsleo avatar mannil avatar nobkd avatar nozomuikuta avatar pi0 avatar renovate[bot] avatar romainlanz avatar tobiasdiez avatar webstrand avatar zuixinwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

destr's Issues

perf: avoid lowercasing long strings

Describe the feature

If the string is longer than nine characters it cannot possibly match any of the hard-coded strings. So wrap the lowercasing operation in a conditional that prevents the operation if the string is ten characters or longer.

Additional information

  • Would you be willing to help implement this feature?

bigint support

Describe the feature

Many of our json data sources come from the backend, and there is an obvious need to convert the long type numbers from the backend into strings for reception (otherwise the precision will be lost), this is json-big (or other Some packages) do, it would be great if this could be supported as a built-in configuration item!

Anyway, json+ts is really nice!

Additional information

  • Would you be willing to help implement this feature?

leading whitespace

TL;DR: After updating "a" laravel package our app broke because destr evaluates all responses as string.

We are using lates laravel as backend with a fairly new plain vue3 frontend.

We are using ofetch (former ohmyfetch) for fetching api responses.
After a update laravel resources responses now have a leading whitespace, thats the reason destr evaluates the response as a string.

How to reproduce:

destr('{}') // type object
destr(' {}') // type text

Is is possible to trim the data before try parsing it?

Compatibility Issues with the String.prototype.at() Method

Environment

"node": ">=16",
"pnpm": ">=8.4.0"

Reproduction

Please use a browser with a version below iOS 14.4 to access.
https://stackblitz.com/edit/typescript-hlusqb?file=index.ts

The results displayed by the Chrome browser on iOS 14.4.

Describe the bug

This is just a compatibility issue. When in iOS 14, an error occurs due to the incompatibility of the browser caused by the use of the "at" method. I'm not sure whether to fix it in this library, compile this library in my project, or provide a polyfill.

System Infomation

Additional context

We use Nuxt (v3.8.2) to develop the application. It is possible that the use of renderJsonPayloads: true in the experimental features causes the data to be parsed with destr. In most cases, this is not a problem, but someone reported a white screen issue on iOS 14.

Logs

No response

QA: parse uncommon properties

There are some properties such as in nuxt content hooks that have this syntax and cannot be parsed.

'content:file:beforeParse'

will this be supported or is it not destr's responsibility?

Memory leak in `destr` package, Nuxt 3 production usage

Hello, @pi0.

I found a memory leak, that affects Nuxt 3 framework, because the destr package is used as default parseResponse option in the ohmyfetch, that used in the Nuxt 3 useFetch() function as $fetch.

Memory leak

Flamegraph

image

Table

image

Memory usage

image

Temporary fix for Nuxt 3

  1. Create a local TypeScript file (lib/use-fetch.ts) with copy of useFetch() function.

  2. Add custom parseResponse() function:

    import type { FetchOptions } from 'ohmyfetch';
    
    /**
     * Parse response
     * @description Replace of `destr()` function to prevent memory leak
     * @param responseText
     */
    const parseResponse: FetchOptions['parseResponse'] = (responseText) => {
      // Send empty string if zero length
      if (responseText.length === 0) {
        return '';
      }
    
      try {
        return JSON.parse(responseText);
      } catch (_e) {
        return responseText;
      }
    };
  3. Replace _fetchOptions constant in the copy of useFetch() function:

      const _fetchOptions = {
        ...opts,
        parseResponse,
        cache: typeof opts.cache === 'boolean' ? undefined : opts.cache
      }
  4. Use patched useFetch() function instead of build-in.

Because, right now there is no way to provide custom parseResponse() function as option of the useFetch() without error.

Best wishes,
Sergey.

parsing decimals incorrectly

Environment

destr: 2.0.1(latest)
nodejs: 18.18.1

Reproduction

const value = Math.random().toString() // => '0.5207845927625354'
destr(value) // => '0.5207845927625354' ❌ should be number
JSON.parse(value) // => 0.5207845927625354 🟒 correct

Describe the bug

Parsing a string of numbers with more than 14 decimals gives incorrect results, it should return the number but actually returns the original string.

This should have something to do with the regex here:

const JsonSigRx = /^\s*["[{]|^\s*-?\d[\d.]{0,14}\s*$/;

Additional context

No response

Logs

No response

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update pnpm to v8.15.6

Detected dependencies

github-actions
.github/workflows/autofix.yml
  • actions/checkout v4
  • actions/setup-node v4
  • autofix-ci/action ea32e3a12414e6d3183163c3424a7d7a8631ad84
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-node v4
  • codecov/codecov-action v4
npm
package.json
  • @hapi/bourne ^3.0.0
  • @vitest/coverage-v8 ^1.4.0
  • changelogen ^0.5.5
  • eslint ^8.57.0
  • eslint-config-unjs ^0.2.1
  • mitata ^0.1.11
  • prettier ^3.2.5
  • secure-json-parse ^2.7.0
  • typescript ^5.4.3
  • unbuild ^2.0.0
  • vitest ^1.4.0
  • pnpm 8.15.5

  • Check this box to trigger a request for Renovate to run again on this repository

better Readme

Describe the feature

"A faster, secure and convenient alternative for JSON.parse.".

It will be interesting versus other JsonParser ...
I dont want to search all tool (maybe twenty) who suggests the same thing (and the latest lol) ...

I have no interest by this package because already 20 or more package do the "same" things and i dont know wich is the best :o .... and why this package is so special ?

Additional information

  • Would you be willing to help implement this feature?

Alternative to JSON.stringify

Describe the feature

Was searching all over unjs repo and Google to find the JSON.stringify equivalent of destr and didn't find anything.

If there's one please provide the name, otherwise take it as a feature request. :)

High appreciation to the unjs ecosystem. πŸ”₯πŸ’šπŸ‘

Additional information

  • Would you be willing to help implement this feature?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.