Giter Club home page Giter Club logo

utils's Introduction

@antfu/utils

NPM version Docs

Opinionated collection of common JavaScript / TypeScript utils by @antfu.

  • Tree-shakable ESM
  • Fully typed - with TSDocs
  • Type utilities - Arrayable<T>, ElementOf<T>, etc.

This package is designed to be used as devDependencies and bundled into your dist.

Sponsors

License

MIT License ยฉ 2021-PRESENT Anthony Fu

utils's People

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  avatar  avatar

utils's Issues

Trying to get in touch regarding a security issue

Hey there!

I'd like to report a security issue but cannot find contact instructions on your repository.

If not a hassle, might you kindly add a SECURITY.md file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.

Thank you for your consideration, and I look forward to hearing from you!

(cc @huntr-helper)

[Feature] built-in `DeepObjectMap`

Hi,

Clear and concise description of the problem

I'm currently using objectMap to transform all empty values to null, but it's not recursive by default.

Suggested solution

This feature request proposes a second deepObjectMap method that would work with nested objects.

Alternative

No response

Additional context

No response

Validations

error during build: TypeError: callback.apply is not a function

Describe the bug

When using the latest version (v6.0.1), build reports an error with the following error message. It is available to use the previous v0.5.2.

image

Reproduction

sorry, Unable to provide

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 AMD Ryzen 5 3550H with Radeon Vega Mobile Gfx
    Memory: 5.51 GB / 14.88 GB
  Binaries:
    Node: 14.19.0 - D:\Programs\nodejs\node.EXE
    Yarn: 1.22.17 - D:\Programs\nodejs\yarn.CMD
    npm: 6.14.16 - D:\Programs\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (106.0.1370.52)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

`math/lerp` test with `lerp(0.2, 0.4, 0.5)` failed

Describe the bug

The lerp method may have accuracy problems when calculating with decimals, which may not matter in some scenarios (such as calculating pixels), but may be confusing in some situations.

// math.test.ts
import { lerp } from './math'

it('lerp', () => {
  expect(lerp(0.2, 0.4, 0.5)).toMatchInlineSnapshot('0.30000000000000004')
})

Reproduction

https://github.com/CatsJuice/mir-antfu-utils-math-lerp-precision

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 67.19 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Safari: 17.0

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Improve Prototype Pollution fix coverage

Clear and concise description of the problem

Re: https://huntr.dev/bounties/009f1cd9-401c-49a7-bd08-be35cff6faef/

Thank you for all your hard work on fixing vulnerabilities on the utils lib.

Even after fix on 7.3, platforms such as SonaType are still flagging this package as insecure because one file wasn't updated (index.js) even though the commonJS and ESM versions are clear.

Quote:

The fix for this vulnerability was released for version 0.7.3 and onwards only on the index.mjs and index.cjs files. However the index.js file remains vulnerable.

Suggested solution

index.js should also include the Prototype Pollution fix

Alternative

No response

Additional context

No response

Validations

`p` method's `concurrency` config seems not working

Describe the bug

I don't know if there's something wrong with the way I'm using it, but no matter how I assign a value to concurrency, all the Promises are always executed at the same time.

// main.ts

import { p } from "@antfu/utils";
import { loadData, sleep } from "./utils";

/**
 * Mock data loading
 * @returns 
 */
export async function loadData() {
  await sleep(Math.random() * 1000)
  return Math.round(Math.random() * 1000)
}

const concurrency = 1
let running = 0

p(
  Array.from({ length: 100 }).map(async (_, i) => {
    console.log(`start, running: ${running++}`)
    const data = await loadData();
    console.log(`end, running: ${running--}`)
    return data;
  }), 
  { concurrency }
)

The result of the above code is that all requests are executed simultaneously and end after a random time.
CleanShot 2023-06-20 at 19 10 43@2x

Reproduction

https://github.com/CatsJuice/mir-antfu-utils-p-not-working

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 101.16 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Safari: 17.0

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Docs not working

Describe the bug

README has docs link to https://www.paka.dev/npm/@antfu/utils however when we visit the site it throws error and renders below:

image

Reproduction

  1. Open link in README:
    image

System Info

n/a

Used Package Manager

n/a

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

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.