npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

loppathsfind

v1.6.5

Published

analog of lodash path with support for arrays as path elements

Downloads

5

Readme

  • текущая библиотека содержит функцию lopPathsFind() и константу ISARR
  • функция lopPathsFind() расширяет возможности lodash.get(). Она позволяет получить значение элемента в глубине объекта, если он расположен в массиве (на любом из уровней объекта), и мы не знаем точно на каком из индексов этого массива (массивов)
  • функция lopPathsFind() решает это за счёт пометки мест расположения массивов, специальной константой ISARR. Путь с такими пометками называется lopPath
  • примеры lopPath:
    • пример 1
      `elems.${ISARR}.name`
      • эта запись говорит что elems это массив, и мы хотим получить все значения ключа name элементов этого массива
    • пример 2
      `${ISARR}.${ISARR}.val`
      • здесь мы хотим искать значение val объекта вложенного в массив, который в свою очередь также вложен в массив
  • функция lopPathsFind() пробегает по всем элементам массивов пути в поисках указанного вами элемента пути
  • сигнатура функции lopPathsFind():
    lopPathsFind(target: any, lopPath: string, predicate?: (val: any) => boolean): RetType[]
    • где
      • target - объект/массив значения из которого мы хотим получить
      • lopPath - lopPath-путь
      • predicate - (опционально) если вы хотите отбирать в итоговый результат не все элементы, а только те которые удовлетворяют этому предикату
      • RetType :
        interface RetType {
          /** путь к значению */
          path: string,
          /** значение */
          value: any
          /** существует ли указанный path; если не существует в `value` будет undefined */
          isHas: boolean;
        }

Примеры

  • пример 1, без 3-го параметра
    import { ISARR, lopPathsFind } from 'loppathsfind';
    
    const obj = {
      a: [
        { b: 1 },
        { c: 2 },
        { c: 3 },
        { c: 2 },
      ],
    };
      
    const lopPath = `a.${ISARR}.c`;
    const result = lopPathsFind(obj, lopPath);
     
    // result
     
    /*
    [
      { path: 'a.0.c', value: undefined, isHas: false },
      { path: 'a.1.c', value: 2, isHas: true },
      { path: 'a.2.c', value: 3, isHas: true },
      { path: 'a.3.c', value: 2, isHas: true }
    ]
    */
  • пример 2, с 3-м параметром
    import { ISARR, lopPathsFind } from 'loppathsfind';
    
    const obj = {
      a: [
        { b: 1 },
        { c: 2 },
        { c: 3 },
        { c: 2 },
      ],
    };
      
    const lopPath = `a.${ISARR}.c`;
    const result = lopPathsFind(obj, lopPath, (val) => val === 2);
     
    // result
     
    /*
    [
      { path: 'a.1.c', value: 2, isHas: true },
      { path: 'a.3.c', value: 2, isHas: true }
    ]
    */
  • также см. тесты - /test/lopPathsFind-ts.test.ts

Разное

  • используемый пакет-менеджер - yarn
  • используется библиотека tsdx для билда текущей библиотеки

Что зачем

  • root/babel.config.js - для Jest
  • root/jest.config.js - для Jest
  • root/tsconfig.json - для TypeScript