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

@wixc3/common

v18.0.0

Published

Common utils, usable in all environments

Downloads

4,368

Readme

npm version @wixc3/common on Github

Home > @wixc3/common

common package

Useful utils for strings, iterables, objects, maps, promises and other commonly used structures

Classes

| Class | Description | | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | ErrorWithCode | Creates an error with error code. Helpful when instanceof can't be used because the error was serialized and then deserialized. | | UnreachableCaseError | Allows the type checker to detect non-exhaustive switch statements. |

Enumerations

| Enumeration | Description | | ------------------------------------------------------------------------------------- | ----------- | | NamingConvention | |

Functions

| Function | Description | | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | addToSet(target, source) | | | assertIsString(value, errorMessage) | Throws if value is not a string | | asyncNoop() | | | at(iterable, index) | Finds element by index, including negative index | | awaitRecord(obj) | Awaits a record of promises, and returns a record of their results. | | capitalizeFirstLetter(val) | Capitalize the first letter of a string | | chain(value) | Chain iterable operations, each acting on the output of the previous step | | chain(value) | Chain iterable operations, each acting on the output of the previous step | | clamp(value, min, max) | | | concat(iterables) | | | createRandomIntWithSeed(seed) | | | defaults(_source, _defaultValues, deep, shouldUseDefault) | Returns an object where missing keys and values/keys that satisfy shouldUseDefault to the value in shouldUseDefault. | | delayed(fn, wait) | Ensures func will be called with at least wait ms between runs. | | enforceSequentialExecution(fn) | Ensures that when the async function fn is called twice in a row, the second call only begins after the first one has finished (successfully or not). | | enumValues(enumObj) | | | enumValues(enumObj) | | | equalIdents(reference, modified, newline) | Matches the indentation of modified to the one of reference | | errorToPlainObject(error) | | | escapeCSS(str) | Replaced non alphanumeric character with CSS unicode representation | | escapeRegExp(str) | Returns a string safe to be used in RegExp | | every(iterable, predicate) | | | exclude(excluded) | | | filter(iterable, predicate) | | | find(iterable, predicate) | | | first(iterable) | Picks the first element of an iterable | | flat(iterable, deep) | | | flatMap(iterable, mapFn) | | | forEach(iterable, fn) | | | get(obj, key) | Similar to Map.get, but works for plain objects, and returns undefined for null maps and missing keys | | get(obj, key) | | | getCartesianProduct(arrays) | | | getErrorCode(error) | Returns error.code property if the error object has it, otherwise returns undefined. | | getIn(obj, path) | | | getOs() | | | getValue(map, key, errorMessage) | Returns a value by key, throws if the value is missing or the map null | | getValue(map, key, errorMessage) | | | getValue(map, key, errorMessage) | | | groupBy(elements, property) | Groups elements by the value of a property | | has(obj, key) | Similar to Map.has, but works for plain objects, and returns false for null maps | | has(obj, key) | Similar to Map.has, but works for plain objects, and returns false for null maps | | has(obj, key) | | | histogram(iterable) | Calculate a histogram of iterable elements | | includes(iterable, item) | | | includesCaseInsensitive(str, substr) | Checks if str contains substr ignoring capitalization | | indexToLineAndColumn(content, pos, newline) | Finds line an column by position index | | isDefined(value) | Given a value of type Nullable, validates value is T | | isEmpty(iterable) | Checks if an iterable is empty | | isErrorLikeObject(error) | Checks if the error is an object compatible with the Error interface; that is, it has properties 'name' and 'message' of type string. The object could be an instance of an Error, or it could be some other kind of object that has these properties. | | isIterable(x) | | | isMap(m) | Validates s is an instance of Map | | isObject(value) | Checks if value is an object, e.g. a plain object, an array, a function, a regex, but not a primitive value.Common usage scenario: |

isObject(value) && value.foo === 'bar';
// Instead of:
typeof value === 'object' && value !== null && 'foo' in value && value.foo === 'bar';

| | isPlainObject(value) | Checks that value is a POJO | | isSet(s) | Validates s is an instance of Set | | isString(value) | Checks is value is a string | | isValidNamingConvention(namingConvention) | Checks if namingConvention is supported | | join(iterable, separator) | | | keys(map) | | | keys(map) | | | last(iterable) | Picks the last element of an iterable | | map(iterable, mapFn) | Map iterable elements | | mapKeys(obj, mapping) | Maps values of a plain object | | mapObject(obj, mapping) | Maps key value pairs of a plain object | | mapValues(obj, mapping) | Maps values of a plain object | | memoize(fn, argsHash) | | | minimalIndent(str) | Shifts all indentation to the left using the line with the least indentation as a baseline | | mulberry32(a) | | | newMacrotask() | | | next(iterable, item) | Find the element following an item | | noIdents(modified, separator) | Remove line indentation (heading whitespace) | | noop() | | | normToRage(normal, min, max) | | | noWhiteSpace(str) | Remove white spaces including empty lines | | once(fn) | Make a function executable only once, following calls are ignored | | partition(data, bucketsCount, predicate) | Partition unordered data into buckets of similar total weight | | pick(record, keys) | returns an object composed of the picked object properties | | prev(iterable, item) | Find the element before an item | | randomizedOrder(size) | | | reduce(iterable, reducer, initial) | | | reportError_2(ex) | Logs an error | | reverseObject(obj) | Reverses keys-values of an object, ignoring falsy values. First takes on value collisions. | | same(a, b, unordered) | Deep comparison of two objects | | seededRandomInt(min, max) | | | shuffle(array) | Shuffles an array | | size(iterable) | Evaluate the size of an iterable | | skip(iterable, count) | Skips the first elements of an iterable | | some(iterable, predicate) | | | sort(iterable, by) | | | splitIntoWords(str) | Breaks down a string to words, dropping non letters and numbers | | stringifyErrorStack(error) | | | swap(array, i, j) | Swaps elements of an array in place | | templateCompilerProvider(context) | Similar to templated string, given a fixed context object returns a function that parses strings in it | | toCamelCase(str) | Converts a string to camelCase | | toCSSCamelCase(str) | like toCamelCase(), but capitalizes first character if input starts with '-' | | toCSSKebabCase(str) | like toKebabCase(), but prepends '-' if first character of input is UpperCase | | toError(value) | Convert any kind of value to an error instance. Unless the value is already an error instance, it's stringified and used as the error message. | | toKebabCase(str) | Converts a string to kebab-case | | toMap(obj) | Coverts and object into a Map | | toNamingConvention(str, namingConvention) | Converts string formatting to a naming convention | | toPascalCase(str) | Converts a string to PascalCase | | toPascalCaseJsIdentifier(str) | Similar to toPascalCase(), but drops heading non-letters | | unique(iterable, by) | Creates iterable of unique elements | | values(map) | | | values(map) | |

Variables

| Variable | Description | | ------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | | isElectronRendererProcess | | | isMac | | | isWindows | | | remap | remaps keys of obj based on rename map object, |

Type Aliases

| Type Alias | Description | | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | | Awaited_2 | The resolved value of T (if a promise, otherwise simply T) | | Chain | | | Flat | | | Iter | | | IterableChain | | | Mapping | | | MapValue | | | NotIterable | | | Nullable | T or null/undefined | | ObjValue | | | Predicate | | | Remap | | | RemapFunc | | | Remapped | | | UnionToIntersection | Make an intersection type from union | | ValueChain | | | ValueOf | union of all fields of T |