core logic for form8ion tools related to JavaScript, like javascript-scaffolder and lift-javascript
npm install @form8ion/javascript-corecoverageShouldBeReported# javascript-core
core logic for form8ion tools related to JavaScript, like
javascript-scaffolder and
lift-javascript
[![Node CI Workflow Status][github-actions-ci-badge]][github-actions-ci-link]
[![Codecov][coverage-badge]][coverage-link]
![SLSA Level 2][slsa-badge]
[![OpenSSF Scorecard][ossfScorecard-badge]][ossfScorecard-link]
* Usage
* Installation
* Example
* Import
* Execute
* API
* scaffoldChoice
* choices __object__ (_required_)
* choice __string__ (_required_)
* options __object__ (_optional_)
* installDependencies
* dependencies __list of strings__ (_required_)
* dependenciesType __string__ (_required_)
* projectRoot __string__ (_optional_)
* packageManger __string__ (_optional_)
* Dependency-types Constants
* projectTypes
* packageManagers
* dialects
* projectTypeShouldBePublished
* projectType __string__ (_required_)
* coverageShouldBeReported
* visibility __string__ (_required_)
* tests __object__ (_required_)
* writePackageJson
* projectRoot __string__ (_required_)
* config __object__ (_required_)
* mergeIntoExistingPackageJson
* projectRoot __string__ (_required_)
* config __object__ (_required_)
* Node version categories
* determineLtsNodeMajorVersions
* withinRange __string__ (_optional_)
* determineSupportedNodeMajorVersions
* withinRange __string__ (_optional_)
* Contributing
* Dependencies
* Verification
[![MIT license][license-badge]][license-link]
[![npm][npm-badge]][npm-link]
![node][node-badge]
[![Try @form8ion/javascript-core on RunKit][runkit-badge]][runkit-link]
``sh`
$ npm install @form8ion/javascript-core --save-prod
#### Import
`javascript`
const {scaffoldChoice} = require('@form8ion/javascript-core');
#### Execute
`javascript`
(async () => {
await scaffoldChoice(
{foo: {scaffold: options => options}},
'foo',
{bar: 'baz'}
);
})();
#### scaffoldChoice
A generic function that executes the scaffolder function from a provided map
of options based on the chosen option name.
Takes three unnamed arguments:
##### choices __object__ (_required_)
* keys: __string__ Name of the choice
* values: __object__
* scaffolder: __function__ (_required_) scaffolds the choice options
##### choice __string__ (_required_)
Name of the choice. SHOULD match a key from the choices object.
##### options __object__ (_optional_)
options object to be passed as the only argument to the chosen scaffolder
#### installDependencies
A function that installs the provided package dependencies.
Takes four unnamed arguments:
##### dependencies __list of strings__ (_required_)
The list of package names to be installed.
##### dependenciesType __string__ (_required_)
Defines if the provided list of package names should be installed as prod or
dev dependencies. If "dev" is provided, the list will be installed with the
--save-exact flag.
##### projectRoot __string__ (_optional_)
Filesystem path to the root of the project
##### packageManger __string__ (_optional_)
Specifies the name of the package manager to be used for dependency
installation. Defaults to npm
###### Dependency-types Constants
Constants to define the valid options for dependenciesType
* PROD_DEPENDENCY_TYPEDEV_DEPENDENCY_TYPE
*
#### projectTypes
Constants defining the types of possible JavaScript projects
* APPLICATIONPACKAGE
* CLI
*
#### packageManagers
Constants defining the available package managers
* NPMYARN
*
#### dialects
Constants defining the available JavaScript source dialects
* COMMON_JSBABEL
* ESM
* TYPESCRIPT
*
#### projectTypeShouldBePublished
Predicate function to determine if the project-type is one
that should be published
Takes one argument:
##### projectType __string__ (_required_)
Should be one of the project-type options
#### coverageShouldBeReported
Predicate function to determine if coverage should be reported
Takes two arguments:
##### visibility __string__ (_required_)
visibility of the project (Public or Private)
##### tests __object__ (_required_)
* unit __boolean__ (_optional_)
Whether the project will be unit-tested
#### writePackageJson
Writes the provided config to the package.json for the project
Accepts an options object as the only argument, with the following properties:
##### projectRoot __string__ (_required_)
Filesystem path to the root of the project
##### config __object__ (_required_)
The config to be written to the package.json as the entire contents of the
file
#### mergeIntoExistingPackageJson
Merges the provided config into the existing package.json for the project
Accepts an options object as the only argument, with the following properties:
##### projectRoot __string__ (_required_)
Filesystem path to the root of the project
##### config __object__ (_required_)
The config to be merged with the existing contents of the package.json
#### Node version categories
Helpers for determining supported node.js versions in categories defined by
package support guidelines.
Refer to the release schedule for
current statuses.
##### determineLtsNodeMajorVersions
Returns a list of the major LTS versions currently in _active_ or _maintenance_
status, optionally filtered by a provided semver range.
Accepts an options object as the only argument, with the following properties:
###### withinRange __string__ (_optional_)
A semver range, compatible with node-semver,
to filter the list of active major LTS versions by.
##### determineSupportedNodeMajorVersions
Returns a list of the major versions currently not in end-of-life status,
optionally filtered by a provided semver range.
Accepts an options object as the only argument, with the following properties:
###### withinRange __string__ (_optional_)
A semver range, compatible with node-semver,
to filter the list of active major LTS versions by.
[![PRs Welcome][PRs-badge]][PRs-link]
[![Conventional Commits][commit-convention-badge]][commit-convention-link]
[![Commitizen friendly][commitizen-badge]][commitizen-link]
[![semantic-release][semantic-release-badge]][semantic-release-link]
[![Renovate][renovate-badge]][renovate-link]
`sh`
$ nvm install
$ npm install
`sh``
$ npm test
[PRs-link]: http://makeapullrequest.com
[PRs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
[node-badge]: https://img.shields.io/node/v/@form8ion/javascript-core?logo=node.js
[commit-convention-link]: https://conventionalcommits.org
[commit-convention-badge]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg
[commitizen-link]: http://commitizen.github.io/cz-cli/
[commitizen-badge]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
[semantic-release-link]: https://github.com/semantic-release/semantic-release
[semantic-release-badge]: https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release
[renovate-link]: https://renovatebot.com
[renovate-badge]: https://img.shields.io/badge/renovate-enabled-brightgreen.svg?logo=renovatebot
[license-link]: LICENSE
[license-badge]: https://img.shields.io/github/license/form8ion/javascript-core.svg?logo=opensourceinitiative
[npm-link]: https://www.npmjs.com/package/@form8ion/javascript-core
[npm-badge]: https://img.shields.io/npm/v/@form8ion/javascript-core?logo=npm
[runkit-link]: https://npm.runkit.com/@form8ion/javascript-core
[runkit-badge]: https://badge.runkitcdn.com/@form8ion/javascript-core.svg
[github-actions-ci-link]: https://github.com/form8ion/javascript-core/actions?query=workflow%3A%22Node.js+CI%22+branch%3Amaster
[github-actions-ci-badge]: https://img.shields.io/github/actions/workflow/status/form8ion/javascript-core/node-ci.yml.svg?branch=master&logo=github
[coverage-link]: https://codecov.io/github/form8ion/javascript-core
[coverage-badge]: https://img.shields.io/codecov/c/github/form8ion/javascript-core?logo=codecov
[slsa-badge]: https://slsa.dev/images/gh-badge-level2.svg
[ossfScorecard-link]: https://securityscorecards.dev/viewer/?uri=github.com/form8ion/javascript-core
[ossfScorecard-badge]: https://api.securityscorecards.dev/projects/github.com/form8ion/javascript-core/badge