@jsenv/url-meta
Advanced tools
Comparing version 6.0.1 to 6.0.3
@@ -1,132 +0,32 @@ | ||
var _defineProperty = (function (obj, key, value) { | ||
// Shortcircuit the slow defineProperty path when possible. | ||
// We are trying to avoid issues where setters defined on the | ||
// prototype cause side effects under the fast path of simple | ||
// assignment. By checking for existence of the property with | ||
// the in operator, we can optimize most of this overhead away. | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
}); | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
var objectWithoutPropertiesLoose = (function (source, excluded) { | ||
if (source === null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key; | ||
var i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
}); | ||
var _objectWithoutProperties = (function (source, excluded) { | ||
if (source === null) return {}; | ||
var target = objectWithoutPropertiesLoose(source, excluded); | ||
var key; | ||
var i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
}); | ||
var assertUrlLike = function assertUrlLike(value) { | ||
var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "url"; | ||
const assertUrlLike = (value, name = "url") => { | ||
if (typeof value !== "string") { | ||
throw new TypeError("".concat(name, " must be a url string, got ").concat(value)); | ||
throw new TypeError(`${name} must be a url string, got ${value}`); | ||
} | ||
if (isWindowsPathnameSpecifier(value)) { | ||
throw new TypeError("".concat(name, " must be a url but looks like a windows pathname, got ").concat(value)); | ||
throw new TypeError(`${name} must be a url but looks like a windows pathname, got ${value}`); | ||
} | ||
if (!hasScheme(value)) { | ||
throw new TypeError("".concat(name, " must be a url and no scheme found, got ").concat(value)); | ||
throw new TypeError(`${name} must be a url and no scheme found, got ${value}`); | ||
} | ||
}; | ||
var isWindowsPathnameSpecifier = function isWindowsPathnameSpecifier(specifier) { | ||
var firstChar = specifier[0]; | ||
const isWindowsPathnameSpecifier = specifier => { | ||
const firstChar = specifier[0]; | ||
if (!/[a-zA-Z]/.test(firstChar)) return false; | ||
var secondChar = specifier[1]; | ||
const secondChar = specifier[1]; | ||
if (secondChar !== ":") return false; | ||
var thirdChar = specifier[2]; | ||
const thirdChar = specifier[2]; | ||
return thirdChar === "/" || thirdChar === "\\"; | ||
}; | ||
var hasScheme = function hasScheme(specifier) { | ||
return /^[a-zA-Z]+:/.test(specifier); | ||
}; | ||
const hasScheme = specifier => /^[a-zA-Z]+:/.test(specifier); | ||
var _excluded$2 = ["pattern", "url"]; | ||
var applyPatternMatching = function applyPatternMatching() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var pattern = _ref.pattern, | ||
url = _ref.url, | ||
rest = _objectWithoutProperties(_ref, _excluded$2); | ||
// https://git-scm.com/docs/gitignore | ||
const applyPatternMatching = ({ | ||
pattern, | ||
url, | ||
...rest | ||
} = {}) => { | ||
assertUrlLike(pattern, "pattern"); | ||
@@ -136,3 +36,7 @@ assertUrlLike(url, "url"); | ||
if (Object.keys(rest).length) { | ||
throw new Error("received more parameters than expected.\n--- name of unexpected parameters ---\n".concat(Object.keys(rest), "\n--- name of expected parameters ---\npattern, url")); | ||
throw new Error(`received more parameters than expected. | ||
--- name of unexpected parameters --- | ||
${Object.keys(rest)} | ||
--- name of expected parameters --- | ||
pattern, url`); | ||
} | ||
@@ -143,7 +47,7 @@ | ||
var applyMatching = function applyMatching(pattern, string) { | ||
var patternIndex = 0; | ||
var index = 0; | ||
var remainingPattern = pattern; | ||
var remainingString = string; // eslint-disable-next-line no-constant-condition | ||
const applyMatching = (pattern, string) => { | ||
let patternIndex = 0; | ||
let index = 0; | ||
let remainingPattern = pattern; | ||
let remainingString = string; // eslint-disable-next-line no-constant-condition | ||
@@ -155,4 +59,4 @@ while (true) { | ||
return pass({ | ||
patternIndex: patternIndex, | ||
index: index | ||
patternIndex, | ||
index | ||
}); | ||
@@ -165,4 +69,4 @@ } // pattern consumed, string not consumed | ||
return fail({ | ||
patternIndex: patternIndex, | ||
index: index | ||
patternIndex, | ||
index | ||
}); | ||
@@ -178,3 +82,3 @@ } // from this point pattern is not consumed | ||
patternIndex: patternIndex + 2, | ||
index: index | ||
index | ||
}); | ||
@@ -185,4 +89,4 @@ } // fail because string shorted than expected | ||
return fail({ | ||
patternIndex: patternIndex, | ||
index: index | ||
patternIndex, | ||
index | ||
}); | ||
@@ -203,4 +107,4 @@ } // from this point pattern and string are not consumed | ||
return fail({ | ||
patternIndex: patternIndex, | ||
index: index | ||
patternIndex, | ||
index | ||
}); | ||
@@ -233,3 +137,3 @@ } // fast path trailing '**' | ||
return pass({ | ||
patternIndex: patternIndex, | ||
patternIndex, | ||
index: string.length | ||
@@ -239,3 +143,3 @@ }); | ||
var skipResult = skipUntilMatch({ | ||
const skipResult = skipUntilMatch({ | ||
pattern: remainingPattern, | ||
@@ -265,7 +169,7 @@ string: remainingString | ||
if (remainingPattern === "") { | ||
var slashIndex = remainingString.indexOf("/"); | ||
const slashIndex = remainingString.indexOf("/"); | ||
if (slashIndex > -1) { | ||
return fail({ | ||
patternIndex: patternIndex, | ||
patternIndex, | ||
index: index + slashIndex | ||
@@ -276,3 +180,3 @@ }); | ||
return pass({ | ||
patternIndex: patternIndex, | ||
patternIndex, | ||
index: string.length | ||
@@ -287,18 +191,16 @@ }); | ||
patternIndex: patternIndex - "*".length, | ||
index: index | ||
index | ||
}); | ||
} | ||
var _skipResult = skipUntilMatch({ | ||
const skipResult = skipUntilMatch({ | ||
pattern: remainingPattern, | ||
string: remainingString, | ||
skippablePredicate: function skippablePredicate(remainingString) { | ||
return remainingString[0] !== "/"; | ||
} | ||
skippablePredicate: remainingString => remainingString[0] !== "/" | ||
}); | ||
if (!_skipResult.matched) { | ||
if (!skipResult.matched) { | ||
return fail({ | ||
patternIndex: patternIndex + _skipResult.patternIndex, | ||
index: index + _skipResult.index | ||
patternIndex: patternIndex + skipResult.patternIndex, | ||
index: index + skipResult.index | ||
}); | ||
@@ -315,4 +217,4 @@ } | ||
return fail({ | ||
patternIndex: patternIndex, | ||
index: index | ||
patternIndex, | ||
index | ||
}); | ||
@@ -330,15 +232,13 @@ } // consumes next char | ||
var skipUntilMatch = function skipUntilMatch(_ref2) { | ||
var pattern = _ref2.pattern, | ||
string = _ref2.string, | ||
_ref2$skippablePredic = _ref2.skippablePredicate, | ||
skippablePredicate = _ref2$skippablePredic === void 0 ? function () { | ||
return true; | ||
} : _ref2$skippablePredic; | ||
var index = 0; | ||
var remainingString = string; | ||
var bestMatch = null; // eslint-disable-next-line no-constant-condition | ||
const skipUntilMatch = ({ | ||
pattern, | ||
string, | ||
skippablePredicate = () => true | ||
}) => { | ||
let index = 0; | ||
let remainingString = string; | ||
let bestMatch = null; // eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
var matchAttempt = applyMatching(pattern, remainingString); | ||
const matchAttempt = applyMatching(pattern, remainingString); | ||
@@ -350,3 +250,3 @@ if (matchAttempt.matched) { | ||
var skippable = skippablePredicate(remainingString); | ||
const skippable = skippablePredicate(remainingString); | ||
bestMatch = fail({ | ||
@@ -366,5 +266,5 @@ patternIndex: bestMatch ? Math.max(bestMatch.patternIndex, matchAttempt.patternIndex) : matchAttempt.patternIndex, | ||
if (remainingString === "") { | ||
bestMatch = _objectSpread2(_objectSpread2({}, bestMatch), {}, { | ||
bestMatch = { ...bestMatch, | ||
index: string.length | ||
}); | ||
}; | ||
break; | ||
@@ -379,36 +279,42 @@ } | ||
var pass = function pass(_ref3) { | ||
var patternIndex = _ref3.patternIndex, | ||
index = _ref3.index; | ||
const pass = ({ | ||
patternIndex, | ||
index | ||
}) => { | ||
return { | ||
matched: true, | ||
index: index, | ||
patternIndex: patternIndex | ||
index, | ||
patternIndex | ||
}; | ||
}; | ||
var fail = function fail(_ref4) { | ||
var patternIndex = _ref4.patternIndex, | ||
index = _ref4.index; | ||
const fail = ({ | ||
patternIndex, | ||
index | ||
}) => { | ||
return { | ||
matched: false, | ||
index: index, | ||
patternIndex: patternIndex | ||
index, | ||
patternIndex | ||
}; | ||
}; | ||
var normalizeStructuredMetaMap = function normalizeStructuredMetaMap(structuredMetaMap, url) { | ||
assertUrlLike(url, "url"); | ||
const normalizeStructuredMetaMap = (structuredMetaMap, baseUrl, ...rest) => { | ||
assertUrlLike(baseUrl, "url"); | ||
if (arguments.length <= 2 ? 0 : arguments.length - 2) { | ||
throw new Error("received more arguments than expected.\n--- number of arguments received ---\n".concat(2 + (arguments.length <= 2 ? 0 : arguments.length - 2), "\n--- number of arguments expected ---\n2")); | ||
if (rest.length) { | ||
throw new Error(`received more arguments than expected. | ||
--- number of arguments received --- | ||
${2 + rest.length} | ||
--- number of arguments expected --- | ||
2`); | ||
} | ||
var structuredMetaMapNormalized = {}; | ||
Object.keys(structuredMetaMap).forEach(function (metaProperty) { | ||
var metaValueMap = structuredMetaMap[metaProperty]; | ||
var metaValueMapNormalized = {}; | ||
Object.keys(metaValueMap).forEach(function (pattern) { | ||
var metaValue = metaValueMap[pattern]; | ||
var specifierResolved = String(new URL(pattern, url)); | ||
const structuredMetaMapNormalized = {}; | ||
Object.keys(structuredMetaMap).forEach(metaProperty => { | ||
const metaValueMap = structuredMetaMap[metaProperty]; | ||
const metaValueMapNormalized = {}; | ||
Object.keys(metaValueMap).forEach(pattern => { | ||
const metaValue = metaValueMap[pattern]; | ||
const specifierResolved = normalizeUrlPattern(pattern, baseUrl); | ||
metaValueMapNormalized[specifierResolved] = metaValue; | ||
@@ -421,13 +327,12 @@ }); | ||
var nativeTypeOf = function nativeTypeOf(obj) { | ||
return typeof obj; | ||
}; | ||
const normalizeUrlPattern = (urlPattern, baseUrl) => { | ||
// starts with a scheme | ||
if (/^[a-zA-Z]{2,}:/.test(urlPattern)) { | ||
return urlPattern; | ||
} | ||
var customTypeOf = function customTypeOf(obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
return String(new URL(urlPattern, baseUrl)); | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? nativeTypeOf : customTypeOf; | ||
var isPlainObject = function isPlainObject(value) { | ||
const isPlainObject = value => { | ||
if (value === null) { | ||
@@ -437,3 +342,3 @@ return false; | ||
if (_typeof(value) === "object") { | ||
if (typeof value === "object") { | ||
if (Array.isArray(value)) { | ||
@@ -449,25 +354,31 @@ return false; | ||
var structuredMetaMapToMetaMap = function structuredMetaMapToMetaMap(structuredMetaMap) { | ||
const structuredMetaMapToMetaMap = (structuredMetaMap, ...rest) => { | ||
if (!isPlainObject(structuredMetaMap)) { | ||
throw new TypeError("structuredMetaMap must be a plain object, got ".concat(structuredMetaMap)); | ||
throw new TypeError(`structuredMetaMap must be a plain object, got ${structuredMetaMap}`); | ||
} | ||
if (arguments.length <= 1 ? 0 : arguments.length - 1) { | ||
throw new Error("received more arguments than expected.\n--- number of arguments received ---\n".concat(1 + (arguments.length <= 1 ? 0 : arguments.length - 1), "\n--- number of arguments expected ---\n1")); | ||
if (rest.length) { | ||
throw new Error(`received more arguments than expected. | ||
--- number of arguments received --- | ||
${1 + rest.length} | ||
--- number of arguments expected --- | ||
1`); | ||
} | ||
var metaMap = {}; | ||
Object.keys(structuredMetaMap).forEach(function (metaProperty) { | ||
var metaValueMap = structuredMetaMap[metaProperty]; | ||
const metaMap = {}; | ||
Object.keys(structuredMetaMap).forEach(metaProperty => { | ||
const metaValueMap = structuredMetaMap[metaProperty]; | ||
if (!isPlainObject(metaValueMap)) { | ||
throw new TypeError("metaValueMap must be plain object, got ".concat(metaValueMap, " for ").concat(metaProperty)); | ||
throw new TypeError(`metaValueMap must be plain object, got ${metaValueMap} for ${metaProperty}`); | ||
} | ||
Object.keys(metaValueMap).forEach(function (pattern) { | ||
var metaValue = metaValueMap[pattern]; | ||
var meta = _defineProperty({}, metaProperty, metaValue); | ||
metaMap[pattern] = pattern in metaMap ? _objectSpread2(_objectSpread2({}, metaMap[pattern]), meta) : meta; | ||
Object.keys(metaValueMap).forEach(pattern => { | ||
const metaValue = metaValueMap[pattern]; | ||
const meta = { | ||
[metaProperty]: metaValue | ||
}; | ||
metaMap[pattern] = pattern in metaMap ? { ...metaMap[pattern], | ||
...meta | ||
} : meta; | ||
}); | ||
@@ -478,43 +389,48 @@ }); | ||
var _excluded$1 = ["url", "structuredMetaMap", "predicate"]; | ||
var urlCanContainsMetaMatching = function urlCanContainsMetaMatching(_ref) { | ||
var url = _ref.url, | ||
structuredMetaMap = _ref.structuredMetaMap, | ||
predicate = _ref.predicate, | ||
rest = _objectWithoutProperties(_ref, _excluded$1); | ||
const urlCanContainsMetaMatching = ({ | ||
url, | ||
structuredMetaMap, | ||
predicate, | ||
...rest | ||
}) => { | ||
assertUrlLike(url, "url"); // the function was meants to be used on url ending with '/' | ||
if (!url.endsWith("/")) { | ||
throw new Error("url should end with /, got ".concat(url)); | ||
throw new Error(`url should end with /, got ${url}`); | ||
} | ||
if (typeof predicate !== "function") { | ||
throw new TypeError("predicate must be a function, got ".concat(predicate)); | ||
throw new TypeError(`predicate must be a function, got ${predicate}`); | ||
} | ||
if (Object.keys(rest).length) { | ||
throw new Error("received more parameters than expected.\n--- name of unexpected parameters ---\n".concat(Object.keys(rest), "\n--- name of expected parameters ---\nurl, structuredMetaMap, predicate")); | ||
throw new Error(`received more parameters than expected. | ||
--- name of unexpected parameters --- | ||
${Object.keys(rest)} | ||
--- name of expected parameters --- | ||
url, structuredMetaMap, predicate`); | ||
} | ||
var metaMap = structuredMetaMapToMetaMap(structuredMetaMap); // for full match we must create an object to allow pattern to override previous ones | ||
const metaMap = structuredMetaMapToMetaMap(structuredMetaMap); // for full match we must create an object to allow pattern to override previous ones | ||
var fullMatchMeta = {}; | ||
var someFullMatch = false; // for partial match, any meta satisfying predicate will be valid because | ||
let fullMatchMeta = {}; | ||
let someFullMatch = false; // for partial match, any meta satisfying predicate will be valid because | ||
// we don't know for sure if pattern will still match for a file inside pathname | ||
var partialMatchMetaArray = []; | ||
Object.keys(metaMap).forEach(function (pattern) { | ||
var meta = metaMap[pattern]; | ||
const partialMatchMetaArray = []; | ||
Object.keys(metaMap).forEach(pattern => { | ||
const meta = metaMap[pattern]; | ||
const { | ||
matched, | ||
index | ||
} = applyPatternMatching({ | ||
pattern, | ||
url | ||
}); | ||
var _applyPatternMatching = applyPatternMatching({ | ||
pattern: pattern, | ||
url: url | ||
}), | ||
matched = _applyPatternMatching.matched, | ||
index = _applyPatternMatching.index; | ||
if (matched) { | ||
someFullMatch = true; | ||
fullMatchMeta = _objectSpread2(_objectSpread2({}, fullMatchMeta), meta); | ||
fullMatchMeta = { ...fullMatchMeta, | ||
...meta | ||
}; | ||
} else if (someFullMatch === false && index >= url.length) { | ||
@@ -529,32 +445,34 @@ partialMatchMetaArray.push(meta); | ||
return partialMatchMetaArray.some(function (partialMatchMeta) { | ||
return predicate(partialMatchMeta); | ||
}); | ||
return partialMatchMetaArray.some(partialMatchMeta => predicate(partialMatchMeta)); | ||
}; | ||
var _excluded = ["url", "structuredMetaMap"]; | ||
var urlToMeta = function urlToMeta() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var url = _ref.url, | ||
structuredMetaMap = _ref.structuredMetaMap, | ||
rest = _objectWithoutProperties(_ref, _excluded); | ||
const urlToMeta = ({ | ||
url, | ||
structuredMetaMap, | ||
...rest | ||
} = {}) => { | ||
assertUrlLike(url); | ||
if (Object.keys(rest).length) { | ||
throw new Error("received more parameters than expected.\n--- name of unexpected parameters ---\n".concat(Object.keys(rest), "\n--- name of expected parameters ---\nurl, structuredMetaMap")); | ||
throw new Error(`received more parameters than expected. | ||
--- name of unexpected parameters --- | ||
${Object.keys(rest)} | ||
--- name of expected parameters --- | ||
url, structuredMetaMap`); | ||
} | ||
var metaMap = structuredMetaMapToMetaMap(structuredMetaMap); | ||
return Object.keys(metaMap).reduce(function (previousMeta, pattern) { | ||
var _applyPatternMatching = applyPatternMatching({ | ||
pattern: pattern, | ||
url: url | ||
}), | ||
matched = _applyPatternMatching.matched; | ||
const metaMap = structuredMetaMapToMetaMap(structuredMetaMap); | ||
return Object.keys(metaMap).reduce((previousMeta, pattern) => { | ||
const { | ||
matched | ||
} = applyPatternMatching({ | ||
pattern, | ||
url | ||
}); | ||
if (matched) { | ||
var meta = metaMap[pattern]; | ||
return _objectSpread2(_objectSpread2({}, previousMeta), meta); | ||
const meta = metaMap[pattern]; | ||
return { ...previousMeta, | ||
...meta | ||
}; | ||
} | ||
@@ -561,0 +479,0 @@ |
{ | ||
"name": "@jsenv/url-meta", | ||
"version": "6.0.1", | ||
"version": "6.0.3", | ||
"description": "Associate data to urls using patterns", | ||
@@ -11,7 +11,6 @@ "license": "MIT", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
"access": "public" | ||
}, | ||
"engines": { | ||
"node": ">=14.12.0" | ||
"node": ">=16.13.0" | ||
}, | ||
@@ -26,2 +25,3 @@ "type": "module", | ||
}, | ||
"main": "./index.js", | ||
"files": [ | ||
@@ -33,5 +33,5 @@ "/dist/", | ||
"scripts": { | ||
"start": "node ./script/start/start_exploring.mjs", | ||
"eslint-check": "node ./node_modules/eslint/bin/eslint.js . --ext=.html,.js,.mjs,.cjs", | ||
"generate-importmap": "node ./script/importmap/generate_importmap.mjs", | ||
"dev": "node ./script/dev/start_dev_server.mjs", | ||
"eslint": "node ./node_modules/eslint/bin/eslint.js . --ext=.html,.js,.mjs,.cjs", | ||
"importmap": "node ./script/importmap/importmap.mjs", | ||
"test": "node --unhandled-rejections=strict ./script/test/test.mjs", | ||
@@ -42,25 +42,23 @@ "test-with-coverage": "npm run test -- --coverage", | ||
"build-commonjs": "node --experimental-import-meta-resolve ./script/build/build_commonjs.mjs", | ||
"prettier-format": "node ./script/prettier/prettier_format.mjs", | ||
"prettier-format-stage": "npm run prettier-format -- --staged", | ||
"prettier-check": "npm run prettier-format -- --dry-run", | ||
"install-playwright": "npx playwright install-deps && npx playwright install", | ||
"prepublishOnly": "node ./script/publish/remove_postinstall.mjs && npm run dist", | ||
"postpublish": "node ./script/publish/restore_postinstall.mjs" | ||
"prettier": "prettier --write .", | ||
"playwright-install": "npx playwright install-deps && npx playwright install", | ||
"prepublishOnly": "npm run dist" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@jsenv/assert": "2.3.1", | ||
"@jsenv/codecov-upload": "3.5.0", | ||
"@jsenv/core": "19.6.2", | ||
"@jsenv/eslint-config": "15.0.2", | ||
"@jsenv/assert": "2.4.1", | ||
"@jsenv/babel-preset": "1.1.2", | ||
"@jsenv/core": "25.1.1", | ||
"@jsenv/eslint-config": "16.0.9", | ||
"@jsenv/file-size-impact": "12.1.1", | ||
"@jsenv/github-release-package": "1.2.3", | ||
"@jsenv/importmap-eslint-resolver": "5.1.0", | ||
"@jsenv/importmap-node-module": "1.0.1", | ||
"@jsenv/importmap-eslint-resolver": "5.2.2", | ||
"@jsenv/importmap-node-module": "5.1.0", | ||
"@jsenv/package-publish": "1.6.2", | ||
"@jsenv/prettier-check-project": "5.6.1", | ||
"eslint": "7.32.0", | ||
"eslint-plugin-html": "6.1.2", | ||
"eslint-plugin-import": "2.24.0", | ||
"prettier": "2.3.2" | ||
"@jsenv/performance-impact": "2.2.1", | ||
"eslint": "8.6.0", | ||
"eslint-plugin-html": "6.2.0", | ||
"eslint-plugin-import": "2.25.4", | ||
"playwright": "1.17.2", | ||
"prettier": "2.5.1" | ||
} | ||
} | ||
} |
@@ -46,3 +46,4 @@ # url-meta | ||
| `**/.*/` | Inside directory starting with a dot | | ||
| `**/node_modules/` | Inside `node_modules` directory | | ||
| `**/node_modules/` | Inside any `node_modules` directory | | ||
| `node_modules/` | Inside root `node_modules` directory | | ||
| `**/*.map` | Ending with `.map` | | ||
@@ -210,4 +211,16 @@ | `**/*.test.*` | Contains `.test.` | | ||
console.log(`${urlA}: ${JSON.stringify(urlToMeta({ url: urlA, specifierMetaMap }), null, " ")}`) | ||
console.log(`${urlB}: ${JSON.stringify(urlToMeta({ url: urlB, specifierMetaMap }), null, " ")}`) | ||
console.log( | ||
`${urlA}: ${JSON.stringify( | ||
urlToMeta({ url: urlA, specifierMetaMap }), | ||
null, | ||
" ", | ||
)}`, | ||
) | ||
console.log( | ||
`${urlB}: ${JSON.stringify( | ||
urlToMeta({ url: urlB, specifierMetaMap }), | ||
null, | ||
" ", | ||
)}`, | ||
) | ||
``` | ||
@@ -214,0 +227,0 @@ |
@@ -109,3 +109,6 @@ // https://git-scm.com/docs/gitignore | ||
const skipResult = skipUntilMatch({ pattern: remainingPattern, string: remainingString }) | ||
const skipResult = skipUntilMatch({ | ||
pattern: remainingPattern, | ||
string: remainingString, | ||
}) | ||
@@ -190,3 +193,7 @@ if (!skipResult.matched) { | ||
const skipUntilMatch = ({ pattern, string, skippablePredicate = () => true }) => { | ||
const skipUntilMatch = ({ | ||
pattern, | ||
string, | ||
skippablePredicate = () => true, | ||
}) => { | ||
let index = 0 | ||
@@ -193,0 +200,0 @@ let remainingString = string |
@@ -6,6 +6,10 @@ export const assertUrlLike = (value, name = "url") => { | ||
if (isWindowsPathnameSpecifier(value)) { | ||
throw new TypeError(`${name} must be a url but looks like a windows pathname, got ${value}`) | ||
throw new TypeError( | ||
`${name} must be a url but looks like a windows pathname, got ${value}`, | ||
) | ||
} | ||
if (!hasScheme(value)) { | ||
throw new TypeError(`${name} must be a url and no scheme found, got ${value}`) | ||
throw new TypeError( | ||
`${name} must be a url and no scheme found, got ${value}`, | ||
) | ||
} | ||
@@ -12,0 +16,0 @@ } |
@@ -5,3 +5,5 @@ import { isPlainObject } from "./isPlainObject.js" | ||
if (!isPlainObject(structuredMetaMap)) { | ||
throw new TypeError(`structuredMetaMap must be a plain object, got ${structuredMetaMap}`) | ||
throw new TypeError( | ||
`structuredMetaMap must be a plain object, got ${structuredMetaMap}`, | ||
) | ||
} | ||
@@ -27,3 +29,4 @@ if (rest.length) { | ||
const meta = { [metaProperty]: metaValue } | ||
metaMap[pattern] = pattern in metaMap ? { ...metaMap[pattern], ...meta } : meta | ||
metaMap[pattern] = | ||
pattern in metaMap ? { ...metaMap[pattern], ...meta } : meta | ||
}) | ||
@@ -30,0 +33,0 @@ }) |
import { assertUrlLike } from "./internal/assertUrlLike.js" | ||
export const normalizeStructuredMetaMap = (structuredMetaMap, url, ...rest) => { | ||
assertUrlLike(url, "url") | ||
export const normalizeStructuredMetaMap = ( | ||
structuredMetaMap, | ||
baseUrl, | ||
...rest | ||
) => { | ||
assertUrlLike(baseUrl, "url") | ||
if (rest.length) { | ||
@@ -19,3 +23,4 @@ throw new Error(`received more arguments than expected. | ||
const metaValue = metaValueMap[pattern] | ||
const specifierResolved = String(new URL(pattern, url)) | ||
const specifierResolved = normalizeUrlPattern(pattern, baseUrl) | ||
metaValueMapNormalized[specifierResolved] = metaValue | ||
@@ -27,1 +32,9 @@ }) | ||
} | ||
const normalizeUrlPattern = (urlPattern, baseUrl) => { | ||
// starts with a scheme | ||
if (/^[a-zA-Z]{2,}:/.test(urlPattern)) { | ||
return urlPattern | ||
} | ||
return String(new URL(urlPattern, baseUrl)) | ||
} |
@@ -5,3 +5,8 @@ import { assertUrlLike } from "./internal/assertUrlLike.js" | ||
export const urlCanContainsMetaMatching = ({ url, structuredMetaMap, predicate, ...rest }) => { | ||
export const urlCanContainsMetaMatching = ({ | ||
url, | ||
structuredMetaMap, | ||
predicate, | ||
...rest | ||
}) => { | ||
assertUrlLike(url, "url") | ||
@@ -53,3 +58,5 @@ // the function was meants to be used on url ending with '/' | ||
return partialMatchMetaArray.some((partialMatchMeta) => predicate(partialMatchMeta)) | ||
return partialMatchMetaArray.some((partialMatchMeta) => | ||
predicate(partialMatchMeta), | ||
) | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
245
0
94275
15
1190