Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsePackage method, bump dependencies, target Node 16 #29

Merged
merged 13 commits into from
Apr 7, 2023

Conversation

tommy-mitchell
Copy link
Contributor

@tommy-mitchell tommy-mitchell commented Apr 6, 2023

Closes #28.

Adds a new parsePackage method that operates on objects and strings:

const package_ = parsePackage({name: 'unicorn', version: '1.0.0'});
//=> NormalizedPackageJson

const package_ = parsePackage('{"name": "unicorn", "version": "1.0.0"}', {normalize: false});
//=> PackageJson

I've bumped the dependencies and the minimum Node.js version as well, so this is a breaking change. With the AVA version bump, I've changed to test script so that we don't have to pass --no-worker-threads and use process.chdir():

"test": "xo && tsd && cd test && ava"

index.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
test/test.js Outdated Show resolved Hide resolved
@tommy-mitchell tommy-mitchell changed the title Add parsePackage method, bump dependencies and Node.js version Add parsePackage method, bump dependencies, target Node 16 Apr 6, 2023
@tommy-mitchell
Copy link
Contributor Author

tommy-mitchell commented Apr 6, 2023

Current checks:

const isObject = packageFile !== null && typeof packageFile === 'object' && !Array.isArray(packageFile);
const isString = typeof packageFile === 'string';

if (!isObject && !isString) {
	throw new TypeError('`packageFile` should be either an `object` or a `string`.');
}

// Input should not be modified - if `structuredClone` is available, do a deep clone, shallow otherwise
const clonedPackageFile = isObject
	? (globalThis.structuredClone === undefined
		? {...packageFile}
		: structuredClone(packageFile))
	: packageFile;

readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
index.js Show resolved Hide resolved
@sindresorhus sindresorhus merged commit 5f28de5 into sindresorhus:main Apr 7, 2023
@tommy-mitchell
Copy link
Contributor Author

@sindresorhus whoops, left in a typo (trailing slash):

image

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.

Add a method/option to read from a string/JSON
2 participants