Skip to content

feat: add objectorarray to replacements - #1049

Open
gameroman wants to merge 1 commit into
e18e:mainfrom
gameroman:objectorarray
Open

feat: add objectorarray to replacements#1049
gameroman wants to merge 1 commit into
e18e:mainfrom
gameroman:objectorarray

Conversation

@gameroman

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Closes #1021

📚 Description

add objectorarray to replacements

@43081j

43081j commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

the package checks if something is an object or an array, but this checks if its an object and not a RegExp.

shouldn't this be typeof and Array.isArray?

@gameroman

Copy link
Copy Markdown
Contributor Author

the package checks if something is an object or an array, but this checks if its an object and not a RegExp.

The package does that https://main.npmx.dev/package-code/objectorarray/v/1.0.5/index.js

@43081j

43081j commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

img

i think maybe the package is just old/terrible? and we should suggest something more sane?

though then it just dumbs down to typeof val === 'object' && val != null. no clue why it special cases RegExp but no other class (e.g. Date, Map, etc).

@gameroman

Copy link
Copy Markdown
Contributor Author

Yeah, I guess it's just because it's old. Array.isArray makes more sense now

@gameroman

Copy link
Copy Markdown
Contributor Author

I think like this

const isPlainObjectOrArray = (val) => {
  if (val === null || typeof val !== 'object') return false
  return Array.isArray(val) || Object.getPrototypeOf(val) === Object.prototype
}

@43081j

43081j commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

it isn't actually checking that it is a plain object it seems.

so it may be even simpler...

@gameroman

Copy link
Copy Markdown
Contributor Author

I think we should keep the snippet as is then, even though the package name is wrong, that's what it does

@43081j

43081j commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

i think it is just poorly named and old, it should be checking if something is an object or an array.

it is trying to do that by checking if it is a non-RegExp object, probably before Array.isArray was a thing.

but this seems as simple as typeof v === 'object' && v != null. that would match all objects and arrays, which is what the name and description of this package claims it exists for.

@gameroman

gameroman commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

The package is used in https://npmx.dev/package/endent made by the same person

All downloads come from there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Replacement]: objectorarray

2 participants