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

javascript-std-lib

v1.19.11

Published

Популярные операции над стандартными типами данных

Downloads

27

Readme

Расширения для стандартной библиотеки JavaScript @esm

Установка

$ npm install javascript-std-lib

Использование

<script type="importmap">
{
  "imports": {
    "javascript-std-lib": "/javascript-std-lib/index.js",
    "javascript-std-lib/": "/javascript-std-lib/library/"
  }
}
</script>
import {Num, Arr, Str, Obj, Fn, Moment} 'javascript-std-lib'; // all static classes
...

Классы

Num - методы для работы с числами

import Num from 'javascript-std-lib/number.js';

//

Num.rand(min, max)                             // rand integer from [min, max)
Num.percent(count, from = 100, precision = 2)  // Num.percent(3, 10) -> 0.3
Num.trunc(num, precision = 2)
Num.pad(5, length = 2, char = '0')             // "05"
Num.sum([1, 2, 3])                             // 6
Num.mean([1, 2, 3, 4])                         // 2.5
Num.percentile(array, percent)
Num.quartile(array, index = 1)
Num.median(array = [])
Num.mode(array = [])
Num.clamp(value, min = 0, max = 1)

Arr - методы для работы с массивами

import Arr from 'javascript-std-lib/array.js';

//

Arr.rand([1, 2, 3, 4, 5, 6, 7]);           // допустим, 5 - случайный элемент массива
Arr.randIndex([1, 2, 3, 4, 5, 6, 7])       // допустим, 3 - случайный индекс из массива
Arr.shuffle([1, 2, 3, 4, 5, 6, 7])         // допустим, [7, 3, 6, 1, 2, 5, 4] - перемешанный массив

Arr.swap([1, 2, 3, 4, 5, 6, 7], 5, 3)      // [1, 2, 3, 6, 5, 4, 7] !!!NOTE @mutable

Arr.uniq([1, 1, 1, 2, 3, 3, 4])            // -> [1, 2, 3, 4]
Arr.uniqObjects(array, path, split = '/')  // Уникальные элементы массива объектов (по полю)

Arr.concat(item => item)                   // (list, item) => list.concat(handler(item)) // для .reduce

Arr.similar([1, 2, 3, 4], [4, 3, 1, 2])    // true, если массивы "похожи"
Arr.included([1, 2, 3, 4, 5], [3, 1, 2])   // true, если элементы второго массива находятся в первом
Arr.intersect([1, 2, 3, 4, 5], [3, 1, 2])  // [1, 2, 3] - пересечение двух массивов
Arr.difference([1, 2, 3, 4, 5], [3, 1, 2]) // [4, 5] - разница двух массивов
Arr.symmetricDifference([1, 2, 3, 4, 5], [3, 1, 2, 6]) // [4, 5, 6]

// Arr.fill(length, any | function)           заполняет массив по паттерну
  Arr.fill(5, 'a')                         // ['a', 'a', 'a', 'a', 'a']
  Arr.fill(5, (_, i) => i + 1)             // [1, 2, 3, 4, 5]

Arr.without([1, 2, 3, 4, 5], 3)            // [1, 2, 4, 5]
Arr.withoutIndex([1, 2, 3, 4, 5], 2)       // [1, 2, 4, 5]

// Arr.groups(array, groups, (item, group) => item === group)
// Группировка элементов массива по другому массиву

// Arr.cartesianProduct(array)                Декартово произведение элементов массива массивов
  Arr.cartesianProduct([[1, 2], 3, [5, 6]])   // [[1, 3, 5], [1, 3, 6], [2, 3, 5], [2, 3, 6]]

Arr.concatMap(array, fn)

Arr.condition([1, 2, 3], e => e % 2 === 0, e => e * 10) // [1, 20, 3]
Arr.filterIndex([1, 2, 3, 4], e => e % 2) // [2, 4]

Str - методы для работы со строками

import Str from 'javascript-std-lib/string.js';

//

Str.is(value) // true, если переданый параметр - строка (без наследования от String @todo)
Str.fill(length, pattern)
Str.random(length, space = 'abc...zyz1...90ABC...XYZ')
Str.matchAll(input, regexp)
Str.format(string, ...args)

Str.cleanRU(string) // !

Obj - методы для работы с объектами

import Obj from 'javascript-std-lib/object.js';

//

Obj.is(value)          // true, если переданый параметр - простой объект
Obj.empty(object)      // true, если переданый параметр - пустой объект (без наследования)
Obj.into(item, object) // boolean, -> item in object
Obj.merge(...objects)
Obj.deep(source)       // deep clone
Obj.arrays(object, key, value) // object[key] = [..., value], return object
Obj.methods(object)    // Список всех методов в прототипе объекта, исключая конструктор

Obj.get(object, path, split = '/')
Obj.set(object, path, value, split = '/')
Obj.paths(object, path = '')
Obj.leafs(object, path = '')
Obj.leafsPaths(object, path = '')
Obj.leafsUpdate(object, migration, path = '')