Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ember-template-lint/todo-utils

Package Overview
Dependencies
Maintainers
4
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ember-template-lint/todo-utils - npm Package Compare versions

Comparing version 9.0.1 to 9.1.0

10

CHANGELOG.md

@@ -0,1 +1,11 @@

## v9.1.0 (2021-06-10)
#### :rocket: Enhancement
* [#242](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/242) Adds new validateConfig function ([@scalvert](https://github.com/scalvert))
* [#238](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/238) Adds new date utils: differenceInDays and format ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v9.0.1 (2021-06-10)

@@ -2,0 +12,0 @@

@@ -16,2 +16,17 @@ /**

export declare function getDatePart(date?: Date): Date;
/**
* Returns the difference in days between two dates.
*
* @param startDate - The start date
* @param endDate - The end date
* @returns a number representing the days between the dates
*/
export declare function differenceInDays(startDate: Date, endDate: Date): number;
/**
* Formats the date in short form, eg. 2021-01-01
*
* @param date - The date to format
* @returns A string representing the formatted date
*/
export declare function format(date: string | number | Date): string;
//# sourceMappingURL=date-utils.d.ts.map

27

lib/date-utils.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDatePart = exports.isExpired = void 0;
exports.format = exports.differenceInDays = exports.getDatePart = exports.isExpired = void 0;
/**

@@ -25,2 +25,27 @@ * Evaluates whether a date is expired (earlier than today)

exports.getDatePart = getDatePart;
/**
* Returns the difference in days between two dates.
*
* @param startDate - The start date
* @param endDate - The end date
* @returns a number representing the days between the dates
*/
function differenceInDays(startDate, endDate) {
const millisecondsPerDay = 86400000;
return Math.round((getDatePart(endDate).getTime() - getDatePart(startDate).getTime()) / millisecondsPerDay);
}
exports.differenceInDays = differenceInDays;
/**
* Formats the date in short form, eg. 2021-01-01
*
* @param date - The date to format
* @returns A string representing the formatted date
*/
function format(date) {
if (!(date instanceof Date)) {
date = new Date(date);
}
return getDatePart(date).toISOString().split('T')[0];
}
exports.format = format;
//# sourceMappingURL=date-utils.js.map

@@ -1,2 +0,8 @@

import { DaysToDecay, TodoConfig } from './types';
import { DaysToDecay, LintTodoPackageJson, TodoConfig } from './types';
declare type ConfigValidationResult = {
pkg?: LintTodoPackageJson;
lintTodorc?: TodoConfig;
isValid: boolean;
message?: string;
};
/**

@@ -54,2 +60,10 @@ * Gets the todo configuration.

export declare function getTodoConfig(baseDir: string, engine: string, customDaysToDecay?: DaysToDecay): TodoConfig;
/**
* Validates whether we have a unique config in a single location.
*
* @param baseDir - The base directory that contains the project's package.json.
* @returns A ConfigValidationResult that indicates whether a config is unique
*/
export declare function validateConfig(baseDir: string): ConfigValidationResult;
export {};
//# sourceMappingURL=todo-config.d.ts.map

49

lib/todo-config.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTodoConfig = void 0;
exports.validateConfig = exports.getTodoConfig = void 0;
const path_1 = require("path");

@@ -80,13 +80,38 @@ /**

exports.getTodoConfig = getTodoConfig;
function getFromConfigFile(basePath, engine) {
const pkg = requireFile(basePath, 'package.json');
const lintTodorc = requireFile(basePath, '.lint-todorc.js');
if ((pkg === null || pkg === void 0 ? void 0 : pkg.lintTodo) && lintTodorc) {
throw new Error('You cannot have todo configurations in both package.json and .lint-todorc.js. Please move the configuration from the package.json to the .lint-todorc.js');
/**
* Validates whether we have a unique config in a single location.
*
* @param baseDir - The base directory that contains the project's package.json.
* @returns A ConfigValidationResult that indicates whether a config is unique
*/
function validateConfig(baseDir) {
const pkg = requireFile(baseDir, 'package.json');
const lintTodorc = requireFile(baseDir, '.lint-todorc.js');
const validationResult = {
pkg,
lintTodorc,
isValid: !((pkg === null || pkg === void 0 ? void 0 : pkg.lintTodo) && lintTodorc),
};
if (!validationResult.isValid) {
validationResult.message =
'You cannot have todo configurations in both package.json and .lint-todorc.js. Please move the configuration from the package.json to the .lint-todorc.js';
}
const todoConfig = lintTodorc !== null && lintTodorc !== void 0 ? lintTodorc : pkg === null || pkg === void 0 ? void 0 : pkg.lintTodo;
return validationResult;
}
exports.validateConfig = validateConfig;
function isTodoConfig(config) {
return (Object.keys(config).length === 0 || Object.prototype.hasOwnProperty.call(config, 'daysToDecay'));
}
function getFromConfigFile(baseDir, engine) {
var _a, _b;
const result = validateConfig(baseDir);
if (!result.isValid) {
throw new Error(result.message);
}
const todoConfig = (_a = result.lintTodorc) !== null && _a !== void 0 ? _a : (_b = result.pkg) === null || _b === void 0 ? void 0 : _b.lintTodo;
if (todoConfig === undefined) {
return;
}
// either an empty config or a legacy config where the object only had a top-level daysToDecay property
if (!todoConfig ||
Object.keys(todoConfig).length === 0 ||
Object.prototype.hasOwnProperty.call(todoConfig, 'daysToDecay')) {
if (isTodoConfig(todoConfig)) {
return todoConfig;

@@ -96,5 +121,5 @@ }

}
function requireFile(basePath, fileName) {
function requireFile(baseDir, fileName) {
try {
return require(path_1.join(basePath, fileName));
return require(path_1.join(baseDir, fileName));
}

@@ -101,0 +126,0 @@ catch (_a) {

{
"name": "@ember-template-lint/todo-utils",
"version": "9.0.1",
"version": "9.1.0",
"repository": "https://github.com/ember-template-lint/ember-template-lint-todo-utils.git",

@@ -22,3 +22,3 @@ "license": "MIT",

"slash": "^3.0.0",
"tslib": "^2.1.0"
"tslib": "^2.2.0"
},

@@ -29,6 +29,6 @@ "devDependencies": {

"@types/tmp": "^0.2.0",
"@typescript-eslint/eslint-plugin": "^4.24.0",
"@typescript-eslint/parser": "^4.25.0",
"date-fns": "^2.22.0",
"eslint": "^7.27.0",
"@typescript-eslint/eslint-plugin": "^4.26.1",
"@typescript-eslint/parser": "^4.26.1",
"date-fns": "^2.22.1",
"eslint": "^7.28.0",
"eslint-config-prettier": "^7.2.0",

@@ -44,3 +44,3 @@ "eslint-plugin-jest": "^24.3.6",

"prettier": "^2.3.0",
"release-it": "^14.7.0",
"release-it": "^14.8.0",
"release-it-lerna-changelog": "^3.1.0",

@@ -47,0 +47,0 @@ "tmp": "^0.2.1",

@@ -89,2 +89,5 @@ # @ember-template-lint/todo-utils

</dd>
<dt><a href="#validateConfig">validateConfig(baseDir)</a> ⇒</dt>
<dd><p>Validates whether we have a unique config in a single location.</p>
</dd>
<dt><a href="#getSeverity">getSeverity(todo, today)</a> ⇒</dt>

@@ -99,2 +102,8 @@ <dd><p>Returns the correct severity level based on the todo data&#39;s decay dates.</p>

</dd>
<dt><a href="#differenceInDays">differenceInDays(startDate, endDate)</a> ⇒</dt>
<dd><p>Returns the difference in days between two dates.</p>
</dd>
<dt><a href="#format">format(date)</a> ⇒</dt>
<dd><p>Formats the date in short form, eg. 2021-01-01</p>
</dd>
</dl>

@@ -412,2 +421,14 @@

- Passed in options override both env vars and package.json config
<a name="validateConfig"></a>
## validateConfig(baseDir) ⇒
Validates whether we have a unique config in a single location.
**Kind**: global function
**Returns**: A ConfigValidationResult that indicates whether a config is unique
| Param | Description |
| --- | --- |
| baseDir | The base directory that contains the project's package.json. |
<a name="getSeverity"></a>

@@ -451,3 +472,28 @@

<a name="differenceInDays"></a>
## differenceInDays(startDate, endDate) ⇒
Returns the difference in days between two dates.
**Kind**: global function
**Returns**: a number representing the days between the dates
| Param | Description |
| --- | --- |
| startDate | The start date |
| endDate | The end date |
<a name="format"></a>
## format(date) ⇒
Formats the date in short form, eg. 2021-01-01
**Kind**: global function
**Returns**: A string representing the formatted date
| Param | Description |
| --- | --- |
| date | The date to format |
<!--DOCS_END-->

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc