Package Exports
- @pelevesque/are-substrings-under-minimum-density
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@pelevesque/are-substrings-under-minimum-density) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
are-substrings-under-minimum-density
Checks if substrings are under minimum densities in a string.
Related Packages
https://github.com/pelevesque/are-substrings-over-maximum-density
https://github.com/pelevesque/are-substrings-under-minimum-occurrences
https://github.com/pelevesque/are-substrings-over-maximum-occurrences
Node Repository
https://www.npmjs.com/package/@pelevesque/are-substrings-under-minimum-density
Installation
npm install @pelevesque/are-substrings-under-minimum-density
Tests
Command | Description |
---|---|
npm test or npm run test |
All Tests Below |
npm run cover |
Standard Style |
npm run standard |
Coverage |
npm run unit |
Unit Tests |
Usage
Requiring
const areSubstringsUnderMinimumDensity = require('@pelevesque/are-substrings-under-minimum-density')
One Check
// under density returns true
// 'a' takes up 50% of the string, less than a 75% density
const str = 'aaaabbbb'
const checks = { a: 0.75 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === true
// equal to density returns false
const str = 'aaaabbbb'
const checks = { a: 0.5 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === false
// over density returns false
const str = 'a man, a hog, and a fly'
const checks = { hog: 0.01 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === false
Multiple Checks
// when one is under density, it returns true ('a' is under 75%)
const str = 'aaaabbbb'
const checks = { a: 0.75, b: 0.5 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === true
// when all are over or equal to density, it returns false
const str = 'aaaabbbb'
const checks = { a: 0.25, bbbb: 0.5 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === false