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

@markuplint/ml-config

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@markuplint/ml-config - npm Package Compare versions

Comparing version 3.0.0-dev.186 to 3.0.0-dev.290

6

lib/index.d.ts

@@ -1,3 +0,3 @@

export * from './merge-config';
export * from './utils';
export * from './types';
export * from './merge-config.js';
export * from './utils.js';
export * from './types.js';

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./merge-config"), exports);
tslib_1.__exportStar(require("./utils"), exports);
tslib_1.__exportStar(require("./types"), exports);
export * from './merge-config.js';
export * from './utils.js';
export * from './types.js';

@@ -1,4 +0,4 @@

import type { Config, AnyRule, AnyRuleV2 } from './types';
import type { Config, AnyRule, AnyRuleV2 } from './types.js';
import type { Nullable } from '@markuplint/shared';
export declare function mergeConfig(a: Config, b: Config): Config;
export declare function mergeRule(a: Nullable<AnyRule | AnyRuleV2>, b: AnyRule | AnyRuleV2): AnyRule;

@@ -1,8 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeRule = exports.mergeConfig = void 0;
const tslib_1 = require("tslib");
const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
const utils_1 = require("./utils");
function mergeConfig(a, b) {
import deepmerge from 'deepmerge';
import { deleteUndefProp, cleanOptions, isRuleConfigValue } from './utils.js';
export function mergeConfig(a, b) {
const config = {

@@ -25,8 +21,6 @@ ...a,

};
(0, utils_1.deleteUndefProp)(config);
deleteUndefProp(config);
return config;
}
exports.mergeConfig = mergeConfig;
function mergeRule(a, b) {
var _a, _b, _c;
export function mergeRule(a, b) {
const oA = optimizeRule(a);

@@ -37,7 +31,7 @@ const oB = optimizeRule(b);

// In short; The `false` makes the rule to be disabled absolutely.
if (oB === false || (!(0, utils_1.isRuleConfigValue)(oB) && (oB === null || oB === void 0 ? void 0 : oB.value) === false)) {
if (oB === false || (!isRuleConfigValue(oB) && oB?.value === false)) {
return false;
}
if (oA === undefined) {
return oB !== null && oB !== void 0 ? oB : {};
return oB ?? {};
}

@@ -47,4 +41,4 @@ if (oB === undefined) {

}
if ((0, utils_1.isRuleConfigValue)(oB)) {
if ((0, utils_1.isRuleConfigValue)(oA)) {
if (isRuleConfigValue(oB)) {
if (isRuleConfigValue(oA)) {
if (Array.isArray(oA) && Array.isArray(oB)) {

@@ -56,10 +50,10 @@ return [...oA, ...oB];

const value = Array.isArray(oA.value) && Array.isArray(oB) ? [...oA.value, ...oB] : oB;
const res = (0, utils_1.cleanOptions)({ ...oA, value });
(0, utils_1.deleteUndefProp)(res);
const res = cleanOptions({ ...oA, value });
deleteUndefProp(res);
return res;
}
const severity = (_a = oB.severity) !== null && _a !== void 0 ? _a : (!(0, utils_1.isRuleConfigValue)(oA) ? oA.severity : undefined);
const value = (_b = oB.value) !== null && _b !== void 0 ? _b : ((0, utils_1.isRuleConfigValue)(oA) ? oA : oA.value);
const options = mergeObject(!(0, utils_1.isRuleConfigValue)(oA) ? oA.options : undefined, oB.options);
const reason = (_c = oB.reason) !== null && _c !== void 0 ? _c : (!(0, utils_1.isRuleConfigValue)(oA) ? oA.reason : undefined);
const severity = oB.severity ?? (!isRuleConfigValue(oA) ? oA.severity : undefined);
const value = oB.value ?? (isRuleConfigValue(oA) ? oA : oA.value);
const options = mergeObject(!isRuleConfigValue(oA) ? oA.options : undefined, oB.options);
const reason = oB.reason ?? (!isRuleConfigValue(oA) ? oA.reason : undefined);
const res = {

@@ -71,15 +65,14 @@ severity,

};
(0, utils_1.deleteUndefProp)(res);
deleteUndefProp(res);
return res;
}
exports.mergeRule = mergeRule;
function mergeObject(a, b) {
if (a == null) {
return b !== null && b !== void 0 ? b : undefined;
return b ?? undefined;
}
if (b == null) {
return a !== null && a !== void 0 ? a : undefined;
return a ?? undefined;
}
const res = (0, deepmerge_1.default)(a, b);
(0, utils_1.deleteUndefProp)(res);
const res = deepmerge(a, b);
deleteUndefProp(res);
return res;

@@ -122,4 +115,4 @@ }

}
a === null || a === void 0 ? void 0 : a.forEach(concat);
b === null || b === void 0 ? void 0 : b.forEach(concat);
a?.forEach(concat);
b?.forEach(concat);
return newArray.length === 0 ? undefined : newArray;

@@ -153,3 +146,3 @@ }

}
(0, utils_1.deleteUndefProp)(res);
deleteUndefProp(res);
return Object.freeze(res);

@@ -171,6 +164,6 @@ }

}
if ((0, utils_1.isRuleConfigValue)(rule)) {
if (isRuleConfigValue(rule)) {
return rule;
}
return (0, utils_1.cleanOptions)(rule);
return cleanOptions(rule);
}

@@ -6,90 +6,82 @@ import type { ParserOptions } from '@markuplint/ml-ast';

export type Config = {
readonly $schema?: string;
readonly extends?: string | readonly string[];
readonly plugins?: readonly (PluginConfig | string)[];
readonly parser?: ParserConfig;
readonly parserOptions?: ParserOptions;
readonly specs?: SpecConfig;
readonly excludeFiles?: readonly string[];
readonly pretenders?: readonly Pretender[];
readonly rules?: Rules;
readonly nodeRules?: readonly NodeRule[];
readonly childNodeRules?: readonly ChildNodeRule[];
readonly overrides?: Readonly<Record<string, OverrideConfig>>;
readonly $schema?: string;
readonly extends?: string | readonly string[];
readonly plugins?: readonly (PluginConfig | string)[];
readonly parser?: ParserConfig;
readonly parserOptions?: ParserOptions;
readonly specs?: SpecConfig;
readonly excludeFiles?: readonly string[];
readonly pretenders?: readonly Pretender[];
readonly rules?: Rules;
readonly nodeRules?: readonly NodeRule[];
readonly childNodeRules?: readonly ChildNodeRule[];
readonly overrides?: Readonly<Record<string, OverrideConfig>>;
};
export type PrimitiveScalar = string | number | boolean;
export type PlainData =
| Nullable<PrimitiveScalar>
| readonly PlainData[]
| {
readonly [key: string]: PlainData | any;
};
export type NonNullablePlainData =
| PrimitiveScalar
| readonly NonNullablePlainData[]
| {
readonly [key: string]: NonNullablePlainData;
};
export type PlainData = Nullable<PrimitiveScalar> | readonly PlainData[] | {
readonly [key: string]: PlainData | any;
};
export type NonNullablePlainData = PrimitiveScalar | readonly NonNullablePlainData[] | {
readonly [key: string]: NonNullablePlainData;
};
export type OverrideConfig = Omit<Config, '$schema' | 'extends' | 'overrides'>;
export type PluginConfig = {
readonly name: string;
readonly settings: Readonly<Record<string, NonNullablePlainData>>;
readonly name: string;
readonly settings: Readonly<Record<string, NonNullablePlainData>>;
};
export type ParserConfig = {
readonly [extensionPattern: string]: string;
readonly [extensionPattern: string]: string;
};
export type SpecConfig = {
readonly [extensionPattern: string]: string;
readonly [extensionPattern: string]: string;
};
export type Pretender = {
/**
* Target node selectors
*/
readonly selector: string;
/**
* If it is a string, it is resolved as an element name.
* An element has the same attributes as the pretended custom element
* because attributes are just inherited.
*
* If it is an Object, It creates the element by that.
*/
readonly as: string | OriginalNode;
/**
* Target node selectors
*/
readonly selector: string;
/**
* If it is a string, it is resolved as an element name.
* An element has the same attributes as the pretended custom element
* because attributes are just inherited.
*
* If it is an Object, It creates the element by that.
*/
readonly as: string | OriginalNode;
};
export type OriginalNode = {
/**
* Element name
*/
readonly element: string;
/**
* Namespace
*
* Supports `"svg"` and `undefined` only.
* If it is `undefined`, the namespace is HTML.
*/
readonly namespace?: 'svg';
/**
* Attributes
*/
readonly attrs?: readonly {
/**
* Attribute name
*/
readonly name: string;
/**
* If it omits this property, the attribute is resolved as a boolean.
*/
readonly value?:
| string
| {
readonly fromAttr: string;
};
}[];
/**
* To have attributes the defined element has.
*/
readonly inheritAttrs?: boolean;
/**
* ARIA properties
*/
readonly aria?: PretenderARIA;
/**
* Element name
*/
readonly element: string;
/**
* Namespace
*
* Supports `"svg"` and `undefined` only.
* If it is `undefined`, the namespace is HTML.
*/
readonly namespace?: 'svg';
/**
* Attributes
*/
readonly attrs?: readonly {
/**
* Attribute name
*/
readonly name: string;
/**
* If it omits this property, the attribute is resolved as a boolean.
*/
readonly value?: string | {
readonly fromAttr: string;
};
}[];
/**
* To have attributes the defined element has.
*/
readonly inheritAttrs?: boolean;
/**
* ARIA properties
*/
readonly aria?: PretenderARIA;
};

@@ -100,13 +92,11 @@ /**

export type PretenderARIA = {
/**
* Accessible name
*
* - If it is `true`, it assumes the element has any text on its accessible name.
* - If it specifies `fromAttr` property, it assumes the accessible name refers to the value of the attribute.
*/
readonly name?:
| boolean
| {
readonly fromAttr: string;
};
/**
* Accessible name
*
* - If it is `true`, it assumes the element has any text on its accessible name.
* - If it specifies `fromAttr` property, it assumes the accessible name refers to the value of the attribute.
*/
readonly name?: boolean | {
readonly fromAttr: string;
};
};

@@ -117,6 +107,3 @@ export type Rule<T extends RuleConfigValue, O extends PlainData = undefined> = RuleConfig<T, O> | Readonly<T> | boolean;

*/
export type RuleV2<T extends RuleConfigValue, O extends PlainData = undefined> =
| RuleConfigV2<T, O>
| Readonly<T>
| boolean;
export type RuleV2<T extends RuleConfigValue, O extends PlainData = undefined> = RuleConfigV2<T, O> | Readonly<T> | boolean;
export type AnyRule = Rule<RuleConfigValue, PlainData>;

@@ -128,9 +115,9 @@ /**

export type Rules = {
readonly [ruleName: string]: AnyRule;
readonly [ruleName: string]: AnyRule;
};
export type RuleConfig<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly severity?: Severity;
readonly value?: Readonly<T>;
readonly options?: Readonly<O>;
readonly reason?: string;
readonly severity?: Severity;
readonly value?: Readonly<T>;
readonly options?: Readonly<O>;
readonly reason?: string;
};

@@ -141,12 +128,12 @@ /**

export type RuleConfigV2<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly severity?: Severity;
readonly value?: Readonly<T>;
readonly reason?: string;
/**
* Old property
*
* @deprecated
* @see {this.options}
*/
readonly option?: Readonly<O>;
readonly severity?: Severity;
readonly value?: Readonly<T>;
readonly reason?: string;
/**
* Old property
*
* @deprecated
* @see {this.options}
*/
readonly option?: Readonly<O>;
};

@@ -156,54 +143,51 @@ export type Severity = 'error' | 'warning' | 'info';

export type NodeRule = {
readonly selector?: string;
readonly regexSelector?: RegexSelector;
readonly categories?: readonly string[];
readonly roles?: readonly string[];
readonly obsolete?: boolean;
readonly rules?: Rules;
readonly selector?: string;
readonly regexSelector?: RegexSelector;
readonly categories?: readonly string[];
readonly roles?: readonly string[];
readonly obsolete?: boolean;
readonly rules?: Rules;
};
export type ChildNodeRule = {
readonly selector?: string;
readonly regexSelector?: RegexSelector;
readonly inheritance?: boolean;
readonly rules?: Rules;
readonly selector?: string;
readonly regexSelector?: RegexSelector;
readonly inheritance?: boolean;
readonly rules?: Rules;
};
export type Report<T extends RuleConfigValue, O extends PlainData = undefined> =
| Report1<T, O>
| Report2
| (Report1<T, O> & Report2);
export type Report<T extends RuleConfigValue, O extends PlainData = undefined> = Report1<T, O> | Report2 | (Report1<T, O> & Report2);
export type Report1<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly message: string;
readonly scope: Scope<T, O>;
readonly message: string;
readonly scope: Scope<T, O>;
};
export type Report2 = {
readonly message: string;
readonly line: number;
readonly col: number;
readonly raw: string;
readonly message: string;
readonly line: number;
readonly col: number;
readonly raw: string;
};
export type Scope<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly rule: RuleInfo<T, O>;
readonly startLine: number;
readonly startCol: number;
readonly raw: string;
readonly rule: RuleInfo<T, O>;
readonly startLine: number;
readonly startCol: number;
readonly raw: string;
};
export type Violation = {
readonly ruleId: string;
readonly severity: Severity;
readonly message: string;
readonly reason?: string;
readonly line: number;
readonly col: number;
readonly raw: string;
readonly ruleId: string;
readonly severity: Severity;
readonly message: string;
readonly reason?: string;
readonly line: number;
readonly col: number;
readonly raw: string;
};
export type RuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = {
readonly disabled: boolean;
readonly severity: Severity;
readonly value: Readonly<T>;
readonly options: Readonly<O>;
readonly reason?: string;
readonly disabled: boolean;
readonly severity: Severity;
readonly value: Readonly<T>;
readonly options: Readonly<O>;
readonly reason?: string;
};
export type GlobalRuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = RuleInfo<T, O> & {
nodeRules: RuleInfo<T, O>[];
childNodeRules: RuleInfo<T, O>[];
nodeRules: RuleInfo<T, O>[];
childNodeRules: RuleInfo<T, O>[];
};

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

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

import type { AnyRule, AnyRuleV2, PlainData, RuleConfig, RuleConfigV2, RuleConfigValue } from './types';
import type { AnyRule, AnyRuleV2, PlainData, RuleConfig, RuleConfigV2, RuleConfigValue } from './types.js';
/**

@@ -10,9 +10,4 @@ * Return undefined if the template doesn't include the variable that is set as a property in data.

export declare function provideValue(template: string, data: Readonly<Record<string, string>>): string | undefined;
export declare function exchangeValueOnRule(
rule: AnyRule | AnyRuleV2,
data: Readonly<Record<string, string>>,
): AnyRule | undefined;
export declare function cleanOptions(
rule: RuleConfig<RuleConfigValue, PlainData> | RuleConfigV2<RuleConfigValue, PlainData>,
): RuleConfig<RuleConfigValue, PlainData>;
export declare function exchangeValueOnRule(rule: AnyRule | AnyRuleV2, data: Readonly<Record<string, string>>): AnyRule | undefined;
export declare function cleanOptions(rule: RuleConfig<RuleConfigValue, PlainData> | RuleConfigV2<RuleConfigValue, PlainData>): RuleConfig<RuleConfigValue, PlainData>;
export declare function isRuleConfigValue(v: any): v is RuleConfigValue;

@@ -19,0 +14,0 @@ /**

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteUndefProp = exports.isRuleConfigValue = exports.cleanOptions = exports.exchangeValueOnRule = exports.provideValue = void 0;
const tslib_1 = require("tslib");
const is_plain_object_1 = require("is-plain-object");
const mustache_1 = tslib_1.__importDefault(require("mustache"));
// @ts-ignore
import { isPlainObject } from 'is-plain-object';
import mustache from 'mustache';
/**

@@ -14,11 +11,10 @@ * Return undefined if the template doesn't include the variable that is set as a property in data.

*/
function provideValue(template, data) {
var _a;
const ast = mustache_1.default.parse(template);
if (ast.length === 1 && ((_a = ast[0]) === null || _a === void 0 ? void 0 : _a[0]) === 'text') {
export function provideValue(template, data) {
const ast = mustache.parse(template);
if (ast.length === 1 && ast[0]?.[0] === 'text') {
// It doesn't have a variable
return template;
}
const noDataResult = mustache_1.default.render(template, {});
const result = mustache_1.default.render(template, data);
const noDataResult = mustache.render(template, {});
const result = mustache.render(template, data);
// Assume variables are empty in the template if it matched.

@@ -30,4 +26,3 @@ if (noDataResult === result) {

}
exports.provideValue = provideValue;
function exchangeValueOnRule(rule, data) {
export function exchangeValueOnRule(rule, data) {
if (isRuleConfigValue(rule)) {

@@ -65,4 +60,3 @@ return exchangeValue(rule, data);

}
exports.exchangeValueOnRule = exchangeValueOnRule;
function cleanOptions(rule) {
export function cleanOptions(rule) {
const res = {

@@ -77,4 +71,3 @@ severity: rule.severity,

}
exports.cleanOptions = cleanOptions;
function isRuleConfigValue(v) {
export function isRuleConfigValue(v) {
switch (typeof v) {

@@ -92,3 +85,2 @@ case 'string':

}
exports.isRuleConfigValue = isRuleConfigValue;
/**

@@ -99,4 +91,4 @@ *

*/
function deleteUndefProp(obj) {
if (!(0, is_plain_object_1.isPlainObject)(obj)) {
export function deleteUndefProp(obj) {
if (!isPlainObject(obj)) {
return;

@@ -110,3 +102,2 @@ }

}
exports.deleteUndefProp = deleteUndefProp;
/**

@@ -113,0 +104,0 @@ * Return options from `options` or `option`

{
"name": "@markuplint/ml-config",
"version": "3.0.0-dev.186+37ceba57",
"version": "3.0.0-dev.290+af676442",
"description": "JSON Schema and TypeScript types of markuplint configure JSON",

@@ -9,3 +9,8 @@ "repository": "git@github.com:markuplint/markuplint.git",

"private": false,
"main": "lib/index.js",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js"
}
},
"types": "lib/index.d.ts",

@@ -23,12 +28,12 @@ "publishConfig": {

"dependencies": {
"@markuplint/ml-ast": "3.0.0-dev.186+37ceba57",
"@markuplint/selector": "3.0.0-dev.186+37ceba57",
"@markuplint/shared": "3.6.1-dev.3156+37ceba57",
"@types/mustache": "^4.2.2",
"@markuplint/ml-ast": "3.0.0-dev.290+af676442",
"@markuplint/selector": "3.0.0-dev.290+af676442",
"@markuplint/shared": "4.0.0-dev.3580+af676442",
"@types/mustache": "^4.2.3",
"deepmerge": "^4.3.1",
"is-plain-object": "^5.0.0",
"mustache": "^4.2.0",
"type-fest": "^3.8.0"
"type-fest": "^4.4.0"
},
"gitHead": "37ceba578aff49e0326c5e374cef3da6be303b25"
"gitHead": "af6764422feecb56d1d84659028f53daf685bb78"
}
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