Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
unit-compare
Advanced tools
Compare date/time and byte units
npm install --save unit-compare
The example below asserts if a number if less then 10 megabytes:
const compare = require('unit-compare');
const n = 1024;
const isLessThen10Mb = compare.isNumber(n).assert('<10mb')
if (isLessThen10Mb) {
console.log(`${n} is less than 10mb`);
}
Assert if a given number against a string byte size expression:
const greaterThan10kb = compare.isNumber(n).assert('>10kb')
Using comparison methods directly:
const greaterThan10kb = compare.isNumber(n).lessThan(10, 'k');
Assert if a given number against a string datetime expression:
const date = moment();
const equalTo10Mins = compare.isDate(date).assert('>10 minutes');
Using comparison methods directly:
const date = moment().subtract(10, 'minutes');
const greaterThan10kb = compare.isDate(date).lessThan(10, 'days');
compare.isDate() -> DateAssertion
Returns an DateAssertion instance.
compare.isNumber() -> ByteAssertion
Returns a ByteAssertion instance.
.assert(sizeExpression) -> boolean
sizeExpression - accepts a positive integer representing the file size. File size units are:
If no unit is specified, bytes is used by default.
Optionally, expressions can be prefixed with a comparison operator, including:
Examples:
.lessThan(int, unit) -> boolean
.greaterThan(int, unit) -> boolean
.equalTo(int, unit) -> boolean
.greaterThanOrEqual(int, unit) -> boolean
.lessThanOrEqual(int, unit) -> boolean
dateExpression - accepts a time unit. Time units are:
If no unit is specified, days is used by default.
Optionally, expressions can be prefixed with a comparison operator, including:
If no comparison operator is specified, equality is used by default.
Examples:
.lessThan(int, timeUnit) -> boolean
.greaterThan(int, timeUnit) -> boolean
.equalTo(int, timeUnit) -> boolean
.greaterThanOrEqual(int, timeUnit) -> boolean
.lessThanOrEqual(int, timeUnit) -> boolean
npm test
To generate a test coverage report:
npm run coverage
npm run lint
to check your code..jsbeautifyrc
to help.FAQs
Compare byte and datetime units
We found that unit-compare demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.