GithubHelp home page GithubHelp logo

openinf / openinf-util-object Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 3.0 544 KB

Common JavaScript object type-related utilities

Home Page: https://github.com/OpenINF/openinf-util-object#readme

License: Other

JavaScript 56.93% TypeScript 43.07%
javascript object type utilities functional predicate helpers helpers-library javascript-library typescript

openinf-util-object's Introduction

OpenINF logo

@openinf/util-object

Common JavaScript object type-related utilities


'View on npm' 'License: MIT/Apache-2.0'


The high-level goal of @openinf/util-object is to serve as a Node.js package containing utilities for common JavaScript object type-related operations primarily enabling users to perform comparisons and analyze object contents. We are constantly working to improve this repository, so please feel free to contribute if you notice any omissions or errors.

Thanks!


Platform: Node.js LTS

Supported Node.js Environments

  • v4:Argon (Ar)
  • v6:Boron (B)
  • v8:Carbon (C)
  • v10:Dubnium (Db)
  • v12:Erbium (Er)
  • v14:Fermium (Fm)
  • v16:Gallium (Ga)
  • v18:Hydrogen (H)

Code Style: Prettier Commit Style: Conventional Commits Chat on Matrix





Table of Contents





Installation Corepack logo


@openinf/util-object runs on supported versions of Node.js and is available via npm, pnpm, or yarn.

Using the npm CLI

See the official documentation for this command for more information.

npm i @openinf/util-object

Using the pnpm CLI

See the official documentation for this command for more information.

pnpm add @openinf/util-object

Using the Yarn 1 CLI (Classic)

See the official documentation for this command for more information.

yarn add @openinf/util-object

Usage

import { hasOwn } from '@openinf/util-object';

export class GhFileImporter {
  constructor(options: GhFileImporterOptions) {
    if (!hasOwn(options, 'destDir')) {
      throw new MissingOptionError('destDir');
    }
  }
}



API

map([opt_initial])T

Returns a map-like object. If opt_initial is provided, copies its own properties into the newly created object.

hasOwn(obj, key)boolean

Checks if the given key is a property in the map.

ownProperty(obj, key)unknown

Returns obj[key] iff key is obj's own property (is not inherited). Otherwise, returns undefined.

deepMerge(target, source, depth)Object

Deep merges source into target.

omit(o, props)Record<string, (number|RegExp)>
objectsEqualShallow(o1, o2)boolean
memo(obj, prop, factory)R

Takes an object, a property name, and a factory function. If the value of the property is undefined, it generates a value with the factory function, updates the object originally passed, and returns the value that was returned by the factory function.

map([opt_initial]) ⇒ T

Returns a map-like object. If opt_initial is provided, copies its own properties into the newly created object.

Kind: global function

Param Type Description
[opt_initial] T This should typically be an object literal.

hasOwn(obj, key) ⇒ boolean

Checks if the given key is a property in the map.

Kind: global function

Param Type Description
obj T a map like property.
key string

ownProperty(obj, key) ⇒ unknown

Returns obj[key] iff key is obj's own property (is not inherited). Otherwise, returns undefined.

Kind: global function

Param Type
obj Record<string, (number|RegExp)>
key string

deepMerge(target, source, depth) ⇒ Object

Deep merges source into target.

Kind: global function
Throws:

  • Error If source contains a circular reference. Note: Only nested objects are deep-merged, primitives and arrays are not.
Param Type Default Description
target Object
source Object
depth number 10 The maximum merge depth. If exceeded, Object.assign will be used instead.

deepMerge~queue : Array<ITargetSourceDepth>

Kind: inner constant of deepMerge

omit(o, props) ⇒ Record<string, (number|RegExp)>

Kind: global function
Returns: Record<string, (number|RegExp)> - An object with the given properties removed.

Param Type Description
o Record<string, (number|RegExp)> An object to remove properties from.
props Array<string> A list of properties to remove from the Object.

objectsEqualShallow(o1, o2) ⇒ boolean

Kind: global function

Param Type
o1 !Record<string, (number|RegExp)> | null | undefined
o2 !Record<string, (number|RegExp)> | null | undefined

memo(obj, prop, factory) ⇒ R

Takes an object, a property name, and a factory function. If the value of the property is undefined, it generates a value with the factory function, updates the object originally passed, and returns the value that was returned by the factory function.

Kind: global function

Param Type
obj T
prop string
factory function







Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. If for whatever reason you spot something to fix but cannot patch it yourself, please open an issue.


License

This project is licensed under either of

at your option.

The SPDX license identifier for this project is MIT OR Apache-2.0.





Show Your Support


If you like the project (or want to bookmark it) —
— give it a star ⭐️ — it will greatly encourage us.



The OpenINF logo

openinf-util-object's People

Contributors

deepsource-autofix[bot] avatar deepsourcebot avatar dependabot[bot] avatar dereknongeneric avatar ignoreintuition avatar renovate-bot avatar renovate[bot] avatar semgrep-bot avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

openinf-util-object's Issues

doc: flaky badge on README

The "TypeScript Types: Included" badge on the README seems to be timing out. I have seen this multiple times for this particular badge and should be corrected. See the screenshot below.

image

[feature request] prevent including unnecessary files in the deployed package

We should consider adding the "files" stanza to the package.json to create an explicit allowlist and prevent deploying any unnecessary files to the npm registry as part of our package. This would be preferable to using a .npmignore file, which we have been doing so far but is expected to quickly become unmanageable as more files are added.

Dependency Dashboard

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

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • build(deps-dev): bump chai to v4.4.1
  • build(deps-dev): bump eslint to v8.57.0
  • build(deps-dev): bump eslint-config-prettier to v8.10.0
  • build(deps-dev): bump eslint-plugin-import to v2.29.1
  • build(deps-dev): bump eslint-plugin-promise to v6.4.0
  • chore(deps): bump ruby to v3.3.3
  • build(deps-dev): bump chai to v5
  • build(deps-dev): bump eslint to v9
  • build(deps-dev): bump eslint-config-prettier to v9
  • build(deps-dev): bump eslint-plugin-regexp to v2
  • build(deps-dev): bump eslint-plugin-simple-import-sort to v12
  • chore(deps): bump actions/checkout action to v4
  • chore(deps): bump actions/setup-node action to v4
  • chore(deps): bump dependabot/fetch-metadata action to v2
  • chore(deps): bump github/codeql-action action to v3
  • chore(deps): bump pnpm to v9
  • chore(deps): bump ubuntu to v22
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

devcontainer
.devcontainer.json
github-actions
.github/workflows/codeql.yml
  • actions/checkout v3
  • actions/setup-node v3.8.0
  • ruby/setup-ruby v1.151.0
  • github/codeql-action v2
  • github/codeql-action v2
.github/workflows/dependabot-auto-rename.yml
  • dependabot/fetch-metadata v1
.github/workflows/semgrep.yml
  • actions/checkout v3
  • ubuntu 20.04
npm
package.json
  • @types/node 20.x.x
  • @typescript-eslint/eslint-plugin 5.59.9
  • @typescript-eslint/parser 5.59.9
  • chai 4.3.7
  • eslint 8.42.0
  • eslint-config-prettier 8.8.0
  • eslint-import-resolver-node 0.3.7
  • eslint-plugin-etc 2.0.3
  • eslint-plugin-import 2.27.5
  • eslint-plugin-prettier 4.2.1
  • eslint-plugin-promise 6.1.1
  • eslint-plugin-regexp 1.15.0
  • eslint-plugin-simple-import-sort 10.0.0
  • jasmine 5.0.1
  • prettier 2.8.8
  • typescript 5.1.3
  • pnpm 8.6.3
nvm
.nvmrc
ruby-version
.ruby-version
  • ruby 3.2.2

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

Hacktoberfest checklist: prepare project for contributions by following best practices

  • Add the “hacktoberfest” topic to your repository to opt-in to Hacktoberfest and indicate you’re looking for contributions.

  • Apply the “hacktoberfest” label to issues you want contributors to help within your GitHub or GitLab project.

  • Add a CONTRIBUTING.md file with contribution guidelines to your repository.

  • Choose issues that have a well-defined scope and are self-contained.

  • Adopt a code of conduct to create a greater sense of inclusion and community for contributors.

  • Be ready to review pull/merge requests, accepting those that are valid by merging them, leaving an overall approving review, or by adding the “hacktoberfest-accepted” label.

  • Reject any spammy requests you receive by labeling them as “spam”, and any other invalid contributions by closing them or labeling them as “invalid”.

Refs: https://hacktoberfest.com/participation/#maintainers

[feature request] add new `isPlainObject` predicate function

The isPlainObject predicate function is another common convenience function in the JS Object domain.

  • It is quite frequently used and would be very helpful to have.
  • It is distinct from the very similar isObject predicate function from @openinf/util-types
  • It is distinct from the isObjectLike predicate function, which is often kept private/internal



const isPlainObject = ( obj ) => {
	return (
		typeof obj === 'object' &&
		obj !== null &&
		obj.constructor === Object &&
		Object.prototype.toString.call( obj ) === '[object Object]'
	);
};



Aside

hopefully not a misnomer due to the existence of plain old Java objects (POJOs), which are also a thing in JS

Open question
would a more rigorous check be necessary to differentiate btwx the two or is it fine?

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.