simple-package-meta
Version:
Easy access to information about the running package.
73 lines (68 loc) • 3.48 kB
Markdown
# simple-package-meta
[](https://github.com/RichardLitt/standard-readme)
[](https://semver.org/spec/v2.0.0.html)
[](https://conventionalcommits.org)
[](https://github.com/Anadian/simple-package-meta/blob/main/LICENSE)
[](https://github.com/Anadian/simple-package-meta/actions/workflows/ci.yml)
[](https://coveralls.io/github/Anadian/simple-package-meta?branch=main)
[](https://www.npmjs.com/package/simple-package-meta)
> Easy access to information about the running package.
# Table of Contents
- [Background](#Background)
- [Install](#Install)
- [Usage](#Usage)
- [API](#API)
- [Contributing](#Contributing)
- [License](#License)
# Background
A simple sort of convenience, sort of learning ECMAscript module package which takes a URL or an object like from `import.meta` and returns an object with information about the file like its name, version, directories and the nearest `package.json`.
# Install
Using [pnpm](https://pnpm.io/cli/add):
```sh
pnpm add --save simple-package-meta
```
It can, of course, also be installed by [NPM](https://docs.npmjs.com/cli/v8/commands/npm-install) or [Yarn](https://yarnpkg.com/getting-started/usage) using the normal methods.
# Usage
```js
import getPackageMeta from 'simple-package-meta'; //The default is just the getPackageMeta function
import * as PackageMetaNS from 'simple-package-meta'; //The whole namespace
var meta_info = getPackageMeta( import.meta ); //Same as PackageMetaNS.getPackageMeta
```
# API
The package comprises a single constructor and two functions.
```js
new PackageMeta( object ); //Can take either a URL string, a URL object or an `import.meta`-like object
```
This creates a new PackageMeta object albeit lacking some information which requires blocking operations; this is made available by importing the entire module namespace with the name `PackageMetaNS.PackageMeta()` and is intended mainly just for debugging or extending the object as generally you're better off using one of the following helper functions.
```js
getPackageMeta( object )
```
The default export, this asynchronously returns a complete PackageMeta object of the structure:
```js
{
name: '',
version: '',
packageJSON: {},
url: '',
filename: '',
dirname: '',
paths: {
packageDirectory: '',
data: '',
config: '',
cache: '',
log: '',
temp: ''
}
}
```
```js
PackageMetaNS.getPackageMetaSync( object )
```
Same as above except synchronous.
# Contributing
Changes are tracked in [CHANGELOG.md](CHANGELOG.md).
# License
MIT ©2022 Anadian
SEE LICENSE IN [LICENSE](LICENSE)
[](http://creativecommons.org/licenses/by-sa/4.0/)This project's documentation is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/).