@fgv/ts-res 4.5.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/ts-res.d.ts +4282 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +79 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/common/conditions.d.ts +148 -0
- package/lib/packlets/common/conditions.d.ts.map +1 -0
- package/lib/packlets/common/conditions.js +50 -0
- package/lib/packlets/common/conditions.js.map +1 -0
- package/lib/packlets/common/convert.d.ts +111 -0
- package/lib/packlets/common/convert.d.ts.map +1 -0
- package/lib/packlets/common/convert.js +173 -0
- package/lib/packlets/common/convert.js.map +1 -0
- package/lib/packlets/common/helpers/conditions.d.ts +39 -0
- package/lib/packlets/common/helpers/conditions.d.ts.map +1 -0
- package/lib/packlets/common/helpers/conditions.js +105 -0
- package/lib/packlets/common/helpers/conditions.js.map +1 -0
- package/lib/packlets/common/helpers/index.d.ts +3 -0
- package/lib/packlets/common/helpers/index.d.ts.map +1 -0
- package/lib/packlets/common/helpers/index.js +40 -0
- package/lib/packlets/common/helpers/index.js.map +1 -0
- package/lib/packlets/common/helpers/resources.d.ts +34 -0
- package/lib/packlets/common/helpers/resources.d.ts.map +1 -0
- package/lib/packlets/common/helpers/resources.js +81 -0
- package/lib/packlets/common/helpers/resources.js.map +1 -0
- package/lib/packlets/common/index.d.ts +7 -0
- package/lib/packlets/common/index.d.ts.map +1 -0
- package/lib/packlets/common/index.js +69 -0
- package/lib/packlets/common/index.js.map +1 -0
- package/lib/packlets/common/resources.d.ts +41 -0
- package/lib/packlets/common/resources.d.ts.map +1 -0
- package/lib/packlets/common/resources.js +30 -0
- package/lib/packlets/common/resources.js.map +1 -0
- package/lib/packlets/common/validate/conditions.d.ts +248 -0
- package/lib/packlets/common/validate/conditions.d.ts.map +1 -0
- package/lib/packlets/common/validate/conditions.js +436 -0
- package/lib/packlets/common/validate/conditions.js.map +1 -0
- package/lib/packlets/common/validate/index.d.ts +5 -0
- package/lib/packlets/common/validate/index.d.ts.map +1 -0
- package/lib/packlets/common/validate/index.js +65 -0
- package/lib/packlets/common/validate/index.js.map +1 -0
- package/lib/packlets/common/validate/regularExpressions.d.ts +39 -0
- package/lib/packlets/common/validate/regularExpressions.d.ts.map +1 -0
- package/lib/packlets/common/validate/regularExpressions.js +63 -0
- package/lib/packlets/common/validate/regularExpressions.js.map +1 -0
- package/lib/packlets/common/validate/resources.d.ts +97 -0
- package/lib/packlets/common/validate/resources.d.ts.map +1 -0
- package/lib/packlets/common/validate/resources.js +171 -0
- package/lib/packlets/common/validate/resources.js.map +1 -0
- package/lib/packlets/conditions/condition.d.ts +91 -0
- package/lib/packlets/conditions/condition.d.ts.map +1 -0
- package/lib/packlets/conditions/condition.js +146 -0
- package/lib/packlets/conditions/condition.js.map +1 -0
- package/lib/packlets/conditions/conditionCollector.d.ts +54 -0
- package/lib/packlets/conditions/conditionCollector.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionCollector.js +72 -0
- package/lib/packlets/conditions/conditionCollector.js.map +1 -0
- package/lib/packlets/conditions/conditionDecls.d.ts +26 -0
- package/lib/packlets/conditions/conditionDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionDecls.js +24 -0
- package/lib/packlets/conditions/conditionDecls.js.map +1 -0
- package/lib/packlets/conditions/conditionSet.d.ts +99 -0
- package/lib/packlets/conditions/conditionSet.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSet.js +164 -0
- package/lib/packlets/conditions/conditionSet.js.map +1 -0
- package/lib/packlets/conditions/conditionSetCollector.d.ts +65 -0
- package/lib/packlets/conditions/conditionSetCollector.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSetCollector.js +90 -0
- package/lib/packlets/conditions/conditionSetCollector.js.map +1 -0
- package/lib/packlets/conditions/conditionSetDecls.d.ts +18 -0
- package/lib/packlets/conditions/conditionSetDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSetDecls.js +24 -0
- package/lib/packlets/conditions/conditionSetDecls.js.map +1 -0
- package/lib/packlets/conditions/conditionToken.d.ts +86 -0
- package/lib/packlets/conditions/conditionToken.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionToken.js +150 -0
- package/lib/packlets/conditions/conditionToken.js.map +1 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts +24 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.js +54 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.js.map +1 -0
- package/lib/packlets/conditions/convert/decls.d.ts +24 -0
- package/lib/packlets/conditions/convert/decls.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/decls.js +111 -0
- package/lib/packlets/conditions/convert/decls.js.map +1 -0
- package/lib/packlets/conditions/convert/index.d.ts +3 -0
- package/lib/packlets/conditions/convert/index.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/index.js +40 -0
- package/lib/packlets/conditions/convert/index.js.map +1 -0
- package/lib/packlets/conditions/index.d.ts +10 -0
- package/lib/packlets/conditions/index.d.ts.map +1 -0
- package/lib/packlets/conditions/index.js +70 -0
- package/lib/packlets/conditions/index.js.map +1 -0
- package/lib/packlets/decisions/abstractDecision.d.ts +39 -0
- package/lib/packlets/decisions/abstractDecision.d.ts.map +1 -0
- package/lib/packlets/decisions/abstractDecision.js +63 -0
- package/lib/packlets/decisions/abstractDecision.js.map +1 -0
- package/lib/packlets/decisions/abstractDecisionCollector.d.ts +59 -0
- package/lib/packlets/decisions/abstractDecisionCollector.d.ts.map +1 -0
- package/lib/packlets/decisions/abstractDecisionCollector.js +92 -0
- package/lib/packlets/decisions/abstractDecisionCollector.js.map +1 -0
- package/lib/packlets/decisions/candidate.d.ts +58 -0
- package/lib/packlets/decisions/candidate.d.ts.map +1 -0
- package/lib/packlets/decisions/candidate.js +80 -0
- package/lib/packlets/decisions/candidate.js.map +1 -0
- package/lib/packlets/decisions/common.d.ts +15 -0
- package/lib/packlets/decisions/common.d.ts.map +1 -0
- package/lib/packlets/decisions/common.js +24 -0
- package/lib/packlets/decisions/common.js.map +1 -0
- package/lib/packlets/decisions/concreteDecision.d.ts +74 -0
- package/lib/packlets/decisions/concreteDecision.d.ts.map +1 -0
- package/lib/packlets/decisions/concreteDecision.js +114 -0
- package/lib/packlets/decisions/concreteDecision.js.map +1 -0
- package/lib/packlets/decisions/decision.d.ts +91 -0
- package/lib/packlets/decisions/decision.d.ts.map +1 -0
- package/lib/packlets/decisions/decision.js +126 -0
- package/lib/packlets/decisions/decision.js.map +1 -0
- package/lib/packlets/decisions/index.d.ts +7 -0
- package/lib/packlets/decisions/index.d.ts.map +1 -0
- package/lib/packlets/decisions/index.js +44 -0
- package/lib/packlets/decisions/index.js.map +1 -0
- package/lib/packlets/import/fsItem.d.ts +99 -0
- package/lib/packlets/import/fsItem.d.ts.map +1 -0
- package/lib/packlets/import/fsItem.js +174 -0
- package/lib/packlets/import/fsItem.js.map +1 -0
- package/lib/packlets/import/importContext.d.ts +85 -0
- package/lib/packlets/import/importContext.d.ts.map +1 -0
- package/lib/packlets/import/importContext.js +94 -0
- package/lib/packlets/import/importContext.js.map +1 -0
- package/lib/packlets/import/importManager.d.ts +93 -0
- package/lib/packlets/import/importManager.d.ts.map +1 -0
- package/lib/packlets/import/importManager.js +133 -0
- package/lib/packlets/import/importManager.js.map +1 -0
- package/lib/packlets/import/importable.d.ts +71 -0
- package/lib/packlets/import/importable.d.ts.map +1 -0
- package/lib/packlets/import/importable.js +35 -0
- package/lib/packlets/import/importable.js.map +1 -0
- package/lib/packlets/import/importers/collectionImporter.d.ts +60 -0
- package/lib/packlets/import/importers/collectionImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/collectionImporter.js +146 -0
- package/lib/packlets/import/importers/collectionImporter.js.map +1 -0
- package/lib/packlets/import/importers/fsItemImporter.d.ts +49 -0
- package/lib/packlets/import/importers/fsItemImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/fsItemImporter.js +120 -0
- package/lib/packlets/import/importers/fsItemImporter.js.map +1 -0
- package/lib/packlets/import/importers/importer.d.ts +31 -0
- package/lib/packlets/import/importers/importer.d.ts.map +1 -0
- package/lib/packlets/import/importers/importer.js +24 -0
- package/lib/packlets/import/importers/importer.js.map +1 -0
- package/lib/packlets/import/importers/index.d.ts +6 -0
- package/lib/packlets/import/importers/index.d.ts.map +1 -0
- package/lib/packlets/import/importers/index.js +43 -0
- package/lib/packlets/import/importers/index.js.map +1 -0
- package/lib/packlets/import/importers/jsonImporter.d.ts +32 -0
- package/lib/packlets/import/importers/jsonImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/jsonImporter.js +140 -0
- package/lib/packlets/import/importers/jsonImporter.js.map +1 -0
- package/lib/packlets/import/importers/pathImporter.d.ts +61 -0
- package/lib/packlets/import/importers/pathImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/pathImporter.js +87 -0
- package/lib/packlets/import/importers/pathImporter.js.map +1 -0
- package/lib/packlets/import/index.d.ts +7 -0
- package/lib/packlets/import/index.d.ts.map +1 -0
- package/lib/packlets/import/index.js +67 -0
- package/lib/packlets/import/index.js.map +1 -0
- package/lib/packlets/qualifier-types/convert.d.ts +19 -0
- package/lib/packlets/qualifier-types/convert.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/convert.js +45 -0
- package/lib/packlets/qualifier-types/convert.js.map +1 -0
- package/lib/packlets/qualifier-types/index.d.ts +8 -0
- package/lib/packlets/qualifier-types/index.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/index.js +68 -0
- package/lib/packlets/qualifier-types/index.js.map +1 -0
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts +56 -0
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/languageQualifierType.js +87 -0
- package/lib/packlets/qualifier-types/languageQualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts +92 -0
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/literalQualifierType.js +114 -0
- package/lib/packlets/qualifier-types/literalQualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts +184 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/qualifierType.js +173 -0
- package/lib/packlets/qualifier-types/qualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts +40 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js +102 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js.map +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +74 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.js +113 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.js.map +1 -0
- package/lib/packlets/qualifiers/convert/decls.d.ts +23 -0
- package/lib/packlets/qualifiers/convert/decls.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/decls.js +71 -0
- package/lib/packlets/qualifiers/convert/decls.js.map +1 -0
- package/lib/packlets/qualifiers/convert/index.d.ts +3 -0
- package/lib/packlets/qualifiers/convert/index.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/index.js +40 -0
- package/lib/packlets/qualifiers/convert/index.js.map +1 -0
- package/lib/packlets/qualifiers/convert/qualifier.d.ts +17 -0
- package/lib/packlets/qualifiers/convert/qualifier.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/qualifier.js +43 -0
- package/lib/packlets/qualifiers/convert/qualifier.js.map +1 -0
- package/lib/packlets/qualifiers/index.d.ts +6 -0
- package/lib/packlets/qualifiers/index.d.ts.map +1 -0
- package/lib/packlets/qualifiers/index.js +66 -0
- package/lib/packlets/qualifiers/index.js.map +1 -0
- package/lib/packlets/qualifiers/qualifier.d.ts +68 -0
- package/lib/packlets/qualifiers/qualifier.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifier.js +87 -0
- package/lib/packlets/qualifiers/qualifier.js.map +1 -0
- package/lib/packlets/qualifiers/qualifierCollector.d.ts +90 -0
- package/lib/packlets/qualifiers/qualifierCollector.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierCollector.js +157 -0
- package/lib/packlets/qualifiers/qualifierCollector.js.map +1 -0
- package/lib/packlets/qualifiers/qualifierDecl.d.ts +46 -0
- package/lib/packlets/qualifiers/qualifierDecl.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierDecl.js +24 -0
- package/lib/packlets/qualifiers/qualifierDecl.js.map +1 -0
- package/lib/packlets/resource-json/convert.d.ts +54 -0
- package/lib/packlets/resource-json/convert.d.ts.map +1 -0
- package/lib/packlets/resource-json/convert.js +139 -0
- package/lib/packlets/resource-json/convert.js.map +1 -0
- package/lib/packlets/resource-json/helpers.d.ts +41 -0
- package/lib/packlets/resource-json/helpers.d.ts.map +1 -0
- package/lib/packlets/resource-json/helpers.js +96 -0
- package/lib/packlets/resource-json/helpers.js.map +1 -0
- package/lib/packlets/resource-json/index.d.ts +9 -0
- package/lib/packlets/resource-json/index.d.ts.map +1 -0
- package/lib/packlets/resource-json/index.js +72 -0
- package/lib/packlets/resource-json/index.js.map +1 -0
- package/lib/packlets/resource-json/json.d.ts +182 -0
- package/lib/packlets/resource-json/json.d.ts.map +1 -0
- package/lib/packlets/resource-json/json.js +24 -0
- package/lib/packlets/resource-json/json.js.map +1 -0
- package/lib/packlets/resource-json/normalized.d.ts +123 -0
- package/lib/packlets/resource-json/normalized.d.ts.map +1 -0
- package/lib/packlets/resource-json/normalized.js +24 -0
- package/lib/packlets/resource-json/normalized.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts +39 -0
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclCollection.js +121 -0
- package/lib/packlets/resource-json/resourceDeclCollection.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts +11 -0
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclContainer.js +24 -0
- package/lib/packlets/resource-json/resourceDeclContainer.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclTree.d.ts +39 -0
- package/lib/packlets/resource-json/resourceDeclTree.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclTree.js +122 -0
- package/lib/packlets/resource-json/resourceDeclTree.js.map +1 -0
- package/lib/packlets/resource-types/index.d.ts +4 -0
- package/lib/packlets/resource-types/index.d.ts.map +1 -0
- package/lib/packlets/resource-types/index.js +41 -0
- package/lib/packlets/resource-types/index.js.map +1 -0
- package/lib/packlets/resource-types/jsonResourceType.d.ts +65 -0
- package/lib/packlets/resource-types/jsonResourceType.d.ts.map +1 -0
- package/lib/packlets/resource-types/jsonResourceType.js +63 -0
- package/lib/packlets/resource-types/jsonResourceType.js.map +1 -0
- package/lib/packlets/resource-types/resourceType.d.ts +87 -0
- package/lib/packlets/resource-types/resourceType.d.ts.map +1 -0
- package/lib/packlets/resource-types/resourceType.js +62 -0
- package/lib/packlets/resource-types/resourceType.js.map +1 -0
- package/lib/packlets/resource-types/resourceTypeCollector.d.ts +30 -0
- package/lib/packlets/resource-types/resourceTypeCollector.d.ts.map +1 -0
- package/lib/packlets/resource-types/resourceTypeCollector.js +65 -0
- package/lib/packlets/resource-types/resourceTypeCollector.js.map +1 -0
- package/lib/packlets/resources/index.d.ts +5 -0
- package/lib/packlets/resources/index.d.ts.map +1 -0
- package/lib/packlets/resources/index.js +42 -0
- package/lib/packlets/resources/index.js.map +1 -0
- package/lib/packlets/resources/resource.d.ts +75 -0
- package/lib/packlets/resources/resource.d.ts.map +1 -0
- package/lib/packlets/resources/resource.js +109 -0
- package/lib/packlets/resources/resource.js.map +1 -0
- package/lib/packlets/resources/resourceBuilder.d.ts +112 -0
- package/lib/packlets/resources/resourceBuilder.d.ts.map +1 -0
- package/lib/packlets/resources/resourceBuilder.js +162 -0
- package/lib/packlets/resources/resourceBuilder.js.map +1 -0
- package/lib/packlets/resources/resourceCandidate.d.ts +102 -0
- package/lib/packlets/resources/resourceCandidate.d.ts.map +1 -0
- package/lib/packlets/resources/resourceCandidate.js +180 -0
- package/lib/packlets/resources/resourceCandidate.js.map +1 -0
- package/lib/packlets/resources/resourceManager.d.ts +104 -0
- package/lib/packlets/resources/resourceManager.d.ts.map +1 -0
- package/lib/packlets/resources/resourceManager.js +193 -0
- package/lib/packlets/resources/resourceManager.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.PathImporter = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const fsItem_1 = require("../fsItem");
|
|
27
|
+
/**
|
|
28
|
+
* {@link Import.Importers.IImporter | Importer} implementation which imports resources from a `FileTree`
|
|
29
|
+
* given a path.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
class PathImporter {
|
|
33
|
+
/**
|
|
34
|
+
* Protected constructor for the {@link Import.Importers.PathImporter | PathImporter}.
|
|
35
|
+
* @param params - Parameters for creating the {@link Import.Importers.PathImporter | PathImporter}.
|
|
36
|
+
*/
|
|
37
|
+
constructor(params) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
/**
|
|
40
|
+
* The types of {@link Import.IImportable | importables} that this importer can handle.
|
|
41
|
+
*/
|
|
42
|
+
this.types = ['path'];
|
|
43
|
+
this.qualifiers = params.qualifiers;
|
|
44
|
+
this.tree = (_a = params.tree) !== null && _a !== void 0 ? _a : ts_utils_1.FileTree.forFilesystem().orThrow();
|
|
45
|
+
this.ignoreFileTypes = (_b = params.ignoreFileTypes) !== null && _b !== void 0 ? _b : [];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new {@link Import.Importers.PathImporter | PathImporter}.
|
|
49
|
+
* @param params - Parameters for creating the {@link Import.Importers.PathImporter | dirPathImporter}.
|
|
50
|
+
* @returns `Success` with the new `PathImporter` if successful, `Failure` with an error message if not.
|
|
51
|
+
*/
|
|
52
|
+
static create(params) {
|
|
53
|
+
return (0, ts_utils_1.captureResult)(() => new PathImporter(params));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* {@inheritdoc Import.Importers.IImporter.import}
|
|
57
|
+
*/
|
|
58
|
+
import(item, __manager) {
|
|
59
|
+
const { value: fsItem, message: getTreeMessage, detail: getTreeDetail } = this._getFileTreeItemFromImportable(item);
|
|
60
|
+
if (getTreeMessage !== undefined) {
|
|
61
|
+
return (0, ts_utils_1.failWithDetail)(getTreeMessage, getTreeDetail === 'skipped' ? 'skipped' : 'failed');
|
|
62
|
+
}
|
|
63
|
+
if (fsItem.item.type === 'file' && this.ignoreFileTypes.includes(fsItem.item.extension)) {
|
|
64
|
+
return (0, ts_utils_1.succeedWithDetail)([], 'processed');
|
|
65
|
+
}
|
|
66
|
+
// extracted characteristics are in the fsItem so add them to the context when
|
|
67
|
+
// that is imported instead of now.
|
|
68
|
+
const context = item.context;
|
|
69
|
+
return (0, ts_utils_1.succeedWithDetail)([{ type: 'fsItem', item: fsItem, context }], 'processed');
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Gets an {@link Import.FsItem | FsItem} from an {@link Import.IImportable | importable}.
|
|
73
|
+
* @param item - The importable to convert.
|
|
74
|
+
* @returns `Success` containing the `FsItem` if successful, `Failure` with an error message if not.
|
|
75
|
+
*/
|
|
76
|
+
_getFileTreeItemFromImportable(item) {
|
|
77
|
+
if (item.type === 'path') {
|
|
78
|
+
if ('path' in item && typeof item.path === 'string') {
|
|
79
|
+
return fsItem_1.FsItem.createForPath(item.path, this.qualifiers, this.tree);
|
|
80
|
+
}
|
|
81
|
+
return (0, ts_utils_1.failWithDetail)(`malformed path importable does not contain a string path`, 'failed');
|
|
82
|
+
}
|
|
83
|
+
return (0, ts_utils_1.failWithDetail)(`${item.type}: invalid importable type for a PathImporter`, 'skipped');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.PathImporter = PathImporter;
|
|
87
|
+
//# sourceMappingURL=pathImporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathImporter.js","sourceRoot":"","sources":["../../../../src/packlets/import/importers/pathImporter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAOuB;AAKvB,sCAAuD;AAYvD;;;;GAIG;AACH,MAAa,YAAY;IAsBvB;;;OAGG;IACH,YAAsB,MAAiC;;QAfvD;;WAEG;QACa,UAAK,GAA0B,CAAC,MAAM,CAAC,CAAC;QAatD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,MAAA,MAAM,CAAC,IAAI,mCAAI,mBAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,CAAC;QAC9D,IAAI,CAAC,eAAe,GAAG,MAAA,MAAM,CAAC,eAAe,mCAAI,EAAE,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,MAAiC;QACpD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACI,MAAM,CACX,IAAiB,EACjB,SAA0B;QAE1B,MAAM,EACJ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,aAAa,EACtB,GAAG,IAAI,CAAC,8BAA8B,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,IAAA,yBAAc,EAAC,cAAc,EAAE,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC5F,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACxF,OAAO,IAAA,4BAAiB,EAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QAC5C,CAAC;QAED,8EAA8E;QAC9E,mCAAmC;QACnC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAE7B,OAAO,IAAA,4BAAiB,EAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;IACrF,CAAC;IAED;;;;OAIG;IACO,8BAA8B,CAAC,IAAiB;QACxD,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACzB,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACpD,OAAO,eAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACrE,CAAC;YACD,OAAO,IAAA,yBAAc,EAAC,0DAA0D,EAAE,QAAQ,CAAC,CAAC;QAC9F,CAAC;QACD,OAAO,IAAA,yBAAc,EAAC,GAAG,IAAI,CAAC,IAAI,8CAA8C,EAAE,SAAS,CAAC,CAAC;IAC/F,CAAC;CACF;AAlFD,oCAkFC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n captureResult,\n DetailedResult,\n failWithDetail,\n Result,\n succeedWithDetail,\n FileTree\n} from '@fgv/ts-utils';\nimport { ResourceManager } from '../../resources';\nimport { IImportable } from '../importable';\nimport { IImporter, ImporterResultDetail } from './importer';\nimport { IReadOnlyQualifierCollector } from '../../qualifiers';\nimport { FsItem, FsItemResultDetail } from '../fsItem';\n\n/**\n * Parameters for creating a {@link Import.Importers.PathImporter | PathImporter}.\n * @public\n */\nexport interface IPathImporterCreateParams {\n qualifiers: IReadOnlyQualifierCollector;\n tree?: FileTree.FileTree;\n ignoreFileTypes?: string[];\n}\n\n/**\n * {@link Import.Importers.IImporter | Importer} implementation which imports resources from a `FileTree`\n * given a path.\n * @public\n */\nexport class PathImporter implements IImporter {\n /**\n * The {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use for this importer.\n */\n public readonly qualifiers: IReadOnlyQualifierCollector;\n\n /**\n * The `FileTree` from which resources will be imported.\n */\n public readonly tree: FileTree.FileTree;\n\n /**\n * The types of {@link Import.IImportable | importables} that this importer can handle.\n */\n public readonly types: ReadonlyArray<string> = ['path'];\n\n /**\n * The types of files to ignore when importing. Any file not ignored is converted\n * to an {@link Import.IImportableFsItem | IImportableFsItem}.\n */\n public readonly ignoreFileTypes: string[];\n\n /**\n * Protected constructor for the {@link Import.Importers.PathImporter | PathImporter}.\n * @param params - Parameters for creating the {@link Import.Importers.PathImporter | PathImporter}.\n */\n protected constructor(params: IPathImporterCreateParams) {\n this.qualifiers = params.qualifiers;\n this.tree = params.tree ?? FileTree.forFilesystem().orThrow();\n this.ignoreFileTypes = params.ignoreFileTypes ?? [];\n }\n\n /**\n * Creates a new {@link Import.Importers.PathImporter | PathImporter}.\n * @param params - Parameters for creating the {@link Import.Importers.PathImporter | dirPathImporter}.\n * @returns `Success` with the new `PathImporter` if successful, `Failure` with an error message if not.\n */\n public static create(params: IPathImporterCreateParams): Result<PathImporter> {\n return captureResult(() => new PathImporter(params));\n }\n\n /**\n * {@inheritdoc Import.Importers.IImporter.import}\n */\n public import(\n item: IImportable,\n __manager: ResourceManager\n ): DetailedResult<IImportable[], ImporterResultDetail> {\n const {\n value: fsItem,\n message: getTreeMessage,\n detail: getTreeDetail\n } = this._getFileTreeItemFromImportable(item);\n if (getTreeMessage !== undefined) {\n return failWithDetail(getTreeMessage, getTreeDetail === 'skipped' ? 'skipped' : 'failed');\n }\n\n if (fsItem.item.type === 'file' && this.ignoreFileTypes.includes(fsItem.item.extension)) {\n return succeedWithDetail([], 'processed');\n }\n\n // extracted characteristics are in the fsItem so add them to the context when\n // that is imported instead of now.\n const context = item.context;\n\n return succeedWithDetail([{ type: 'fsItem', item: fsItem, context }], 'processed');\n }\n\n /**\n * Gets an {@link Import.FsItem | FsItem} from an {@link Import.IImportable | importable}.\n * @param item - The importable to convert.\n * @returns `Success` containing the `FsItem` if successful, `Failure` with an error message if not.\n */\n protected _getFileTreeItemFromImportable(item: IImportable): DetailedResult<FsItem, FsItemResultDetail> {\n if (item.type === 'path') {\n if ('path' in item && typeof item.path === 'string') {\n return FsItem.createForPath(item.path, this.qualifiers, this.tree);\n }\n return failWithDetail(`malformed path importable does not contain a string path`, 'failed');\n }\n return failWithDetail(`${item.type}: invalid importable type for a PathImporter`, 'skipped');\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/import/index.ts"],"names":[],"mappings":"AAsBA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAEhC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
40
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
41
|
+
};
|
|
42
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
43
|
+
var ownKeys = function(o) {
|
|
44
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
45
|
+
var ar = [];
|
|
46
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
47
|
+
return ar;
|
|
48
|
+
};
|
|
49
|
+
return ownKeys(o);
|
|
50
|
+
};
|
|
51
|
+
return function (mod) {
|
|
52
|
+
if (mod && mod.__esModule) return mod;
|
|
53
|
+
var result = {};
|
|
54
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
55
|
+
__setModuleDefault(result, mod);
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
})();
|
|
59
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
+
exports.Importers = void 0;
|
|
61
|
+
__exportStar(require("./importContext"), exports);
|
|
62
|
+
__exportStar(require("./importable"), exports);
|
|
63
|
+
__exportStar(require("./fsItem"), exports);
|
|
64
|
+
__exportStar(require("./importManager"), exports);
|
|
65
|
+
const Importers = __importStar(require("./importers"));
|
|
66
|
+
exports.Importers = Importers;
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/import/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAAgC;AAChC,+CAA6B;AAC7B,2CAAyB;AACzB,kDAAgC;AAEhC,uDAAyC;AAChC,8BAAS","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './importContext';\nexport * from './importable';\nexport * from './fsItem';\nexport * from './importManager';\n\nimport * as Importers from './importers';\nexport { Importers };\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Converter } from '@fgv/ts-utils';
|
|
2
|
+
import { QualifierType } from './qualifierType';
|
|
3
|
+
import { ReadOnlyQualifierTypeCollector } from './qualifierTypeCollector';
|
|
4
|
+
/**
|
|
5
|
+
* Context necessary to convert a qualifier name or number to an
|
|
6
|
+
* instantiated {@link QualifierTypes.QualifierType}.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IQualifierTypeConvertContext {
|
|
10
|
+
qualifierTypes: ReadOnlyQualifierTypeCollector;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Converter for {@link QualifierTypes.QualifierType | QualifierType} objects,
|
|
14
|
+
* retrieves a {@link QualifierTypes.QualifierType | QualifierType} by name or
|
|
15
|
+
* index from a supplied {@link QualifierTypes.Convert.IQualifierTypeConvertContext | conversion context}.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export declare const qualifierType: Converter<QualifierType, IQualifierTypeConvertContext>;
|
|
19
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/convert.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAA4B,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE1E;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC3C,cAAc,EAAE,8BAA8B,CAAC;CAChD;AAED;;;;;GAKG;AAEH,eAAO,MAAM,aAAa,wDAgBzB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.qualifierType = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
/**
|
|
27
|
+
* Converter for {@link QualifierTypes.QualifierType | QualifierType} objects,
|
|
28
|
+
* retrieves a {@link QualifierTypes.QualifierType | QualifierType} by name or
|
|
29
|
+
* index from a supplied {@link QualifierTypes.Convert.IQualifierTypeConvertContext | conversion context}.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
// eslint-disable-next-line @rushstack/typedef-var
|
|
33
|
+
exports.qualifierType = ts_utils_1.Converters.generic((from, __self, context) => {
|
|
34
|
+
if (!context) {
|
|
35
|
+
return (0, ts_utils_1.fail)('qualifierType converter requires a context');
|
|
36
|
+
}
|
|
37
|
+
if (typeof from === 'string') {
|
|
38
|
+
return context.qualifierTypes.validating.get(from);
|
|
39
|
+
}
|
|
40
|
+
else if (typeof from === 'number') {
|
|
41
|
+
return context.qualifierTypes.getAt(from);
|
|
42
|
+
}
|
|
43
|
+
return (0, ts_utils_1.fail)('qualifierType converter requires a string or number');
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/convert.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAoE;AAapE;;;;;GAKG;AACH,kDAAkD;AACrC,QAAA,aAAa,GAAG,qBAAU,CAAC,OAAO,CAC7C,CACE,IAAa,EACb,MAA8D,EAC9D,OAAsC,EACf,EAAE;IACzB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAA,eAAI,EAAC,4CAA4C,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,IAAA,eAAI,EAAC,qDAAqD,CAAC,CAAC;AACrE,CAAC,CACF,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Converter, Converters, Result, fail } from '@fgv/ts-utils';\nimport { QualifierType } from './qualifierType';\nimport { ReadOnlyQualifierTypeCollector } from './qualifierTypeCollector';\n\n/**\n * Context necessary to convert a qualifier name or number to an\n * instantiated {@link QualifierTypes.QualifierType}.\n * @public\n */\nexport interface IQualifierTypeConvertContext {\n qualifierTypes: ReadOnlyQualifierTypeCollector;\n}\n\n/**\n * Converter for {@link QualifierTypes.QualifierType | QualifierType} objects,\n * retrieves a {@link QualifierTypes.QualifierType | QualifierType} by name or\n * index from a supplied {@link QualifierTypes.Convert.IQualifierTypeConvertContext | conversion context}.\n * @public\n */\n// eslint-disable-next-line @rushstack/typedef-var\nexport const qualifierType = Converters.generic<QualifierType, IQualifierTypeConvertContext>(\n (\n from: unknown,\n __self: Converter<QualifierType, IQualifierTypeConvertContext>,\n context?: IQualifierTypeConvertContext\n ): Result<QualifierType> => {\n if (!context) {\n return fail('qualifierType converter requires a context');\n }\n if (typeof from === 'string') {\n return context.qualifierTypes.validating.get(from);\n } else if (typeof from === 'number') {\n return context.qualifierTypes.getAt(from);\n }\n return fail('qualifierType converter requires a string or number');\n }\n);\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as Convert from './convert';
|
|
2
|
+
export * from './qualifierType';
|
|
3
|
+
export * from './languageQualifierType';
|
|
4
|
+
export * from './literalQualifierType';
|
|
5
|
+
export * from './territoryQualifierType';
|
|
6
|
+
export * from './qualifierTypeCollector';
|
|
7
|
+
export { Convert };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
57
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
58
|
+
};
|
|
59
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
+
exports.Convert = void 0;
|
|
61
|
+
const Convert = __importStar(require("./convert"));
|
|
62
|
+
exports.Convert = Convert;
|
|
63
|
+
__exportStar(require("./qualifierType"), exports);
|
|
64
|
+
__exportStar(require("./languageQualifierType"), exports);
|
|
65
|
+
__exportStar(require("./literalQualifierType"), exports);
|
|
66
|
+
__exportStar(require("./territoryQualifierType"), exports);
|
|
67
|
+
__exportStar(require("./qualifierTypeCollector"), exports);
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,mDAAqC;AAQ5B,0BAAO;AANhB,kDAAgC;AAChC,0DAAwC;AACxC,yDAAuC;AACvC,2DAAyC;AACzC,2DAAyC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Convert from './convert';\n\nexport * from './qualifierType';\nexport * from './languageQualifierType';\nexport * from './literalQualifierType';\nexport * from './territoryQualifierType';\nexport * from './qualifierTypeCollector';\n\nexport { Convert };\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { ConditionOperator, QualifierConditionValue, QualifierContextValue, QualifierMatchScore } from '../common';
|
|
3
|
+
import { IQualifierTypeCreateParams, QualifierType } from './qualifierType';
|
|
4
|
+
/**
|
|
5
|
+
* Interface defining the parameters that can be used to create a new
|
|
6
|
+
* {@link QualifierTypes.LanguageQualifierType | LanguageQualifierType}.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ILanguageQualifierTypeCreateParams extends Partial<IQualifierTypeCreateParams> {
|
|
10
|
+
/**
|
|
11
|
+
* Optional name for the qualifier type. Defaults to 'language'.
|
|
12
|
+
*/
|
|
13
|
+
name?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional flag indicating whether the context can be a list of values.
|
|
16
|
+
* Defaults to `true`.
|
|
17
|
+
*/
|
|
18
|
+
allowContextList?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* {@link QualifierTypes.QualifierType | Qualifier type} which matches BCP-47 language tags applying
|
|
22
|
+
* {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-bcp47#tag-matching | similarity matching}.
|
|
23
|
+
* Accepts a list of language tags in the context by default.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare class LanguageQualifierType extends QualifierType {
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new instance of a {@link QualifierTypes.LanguageQualifierType | language qualifier type}.
|
|
29
|
+
* @param name - Optional name for the qualifier type. Defaults to 'language'.
|
|
30
|
+
* @param allowContextList - Optional flag indicating whether the context can be a list of values. Defaults to `true`.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
protected constructor({ name, allowContextList, index }: ILanguageQualifierTypeCreateParams);
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new instance of a {@link QualifierTypes.LanguageQualifierType | language qualifier type}.
|
|
36
|
+
* @param params - Optional {@link QualifierTypes.ILanguageQualifierTypeCreateParams | parameters} to use when creating
|
|
37
|
+
* the new instance.
|
|
38
|
+
* @returns `Success` with the new {@link QualifierTypes.LanguageQualifierType | language qualifier type} if successful, `Failure`
|
|
39
|
+
* otherwise.
|
|
40
|
+
*/
|
|
41
|
+
static create(params?: ILanguageQualifierTypeCreateParams): Result<LanguageQualifierType>;
|
|
42
|
+
/**
|
|
43
|
+
* {@inheritdoc QualifierTypes.IQualifierType.isValidConditionValue}
|
|
44
|
+
*/
|
|
45
|
+
isValidConditionValue(value: string): value is QualifierConditionValue;
|
|
46
|
+
/**
|
|
47
|
+
* Matches a single language condition against a single language context value using
|
|
48
|
+
* {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-bcp47#tag-matching | similarity matching}.
|
|
49
|
+
* @param condition - The language condition value to match.
|
|
50
|
+
* @param context - The language context value to match against.
|
|
51
|
+
* @param operator - The operator to use for the match. Must be 'matches'.
|
|
52
|
+
* @returns - The match score, or `noMatch` if the match fails.
|
|
53
|
+
*/
|
|
54
|
+
protected _matchOne(condition: QualifierConditionValue, context: QualifierContextValue, operator: ConditionOperator): QualifierMatchScore;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=languageQualifierType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"languageQualifierType.d.ts","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/languageQualifierType.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AAEtD,OAAO,EACL,iBAAiB,EAGjB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EAEpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,kCAAmC,SAAQ,OAAO,CAAC,0BAA0B,CAAC;IAC7F;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,aAAa;IACtD;;;;;OAKG;IACH,SAAS,aAAa,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,kCAAkC;IAa3F;;;;;;OAMG;WACW,MAAM,CAAC,MAAM,CAAC,EAAE,kCAAkC,GAAG,MAAM,CAAC,qBAAqB,CAAC;IAMhG;;OAEG;IACI,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,uBAAuB;IAI7E;;;;;;;OAOG;IACH,SAAS,CAAC,SAAS,CACjB,SAAS,EAAE,uBAAuB,EAClC,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,EAAE,iBAAiB,GAC1B,mBAAmB;CASvB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.LanguageQualifierType = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const ts_bcp47_1 = require("@fgv/ts-bcp47");
|
|
27
|
+
const common_1 = require("../common");
|
|
28
|
+
const qualifierType_1 = require("./qualifierType");
|
|
29
|
+
/**
|
|
30
|
+
* {@link QualifierTypes.QualifierType | Qualifier type} which matches BCP-47 language tags applying
|
|
31
|
+
* {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-bcp47#tag-matching | similarity matching}.
|
|
32
|
+
* Accepts a list of language tags in the context by default.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
class LanguageQualifierType extends qualifierType_1.QualifierType {
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new instance of a {@link QualifierTypes.LanguageQualifierType | language qualifier type}.
|
|
38
|
+
* @param name - Optional name for the qualifier type. Defaults to 'language'.
|
|
39
|
+
* @param allowContextList - Optional flag indicating whether the context can be a list of values. Defaults to `true`.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
constructor({ name, allowContextList, index }) {
|
|
43
|
+
allowContextList = allowContextList !== false;
|
|
44
|
+
/* c8 ignore next 2 - coverage intermittently drops these two lines even though they're tested */
|
|
45
|
+
name = name !== null && name !== void 0 ? name : 'language';
|
|
46
|
+
const validated = index ? { index: common_1.Convert.qualifierTypeIndex.convert(index).orThrow() } : {};
|
|
47
|
+
super(Object.assign({ name,
|
|
48
|
+
allowContextList }, validated));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new instance of a {@link QualifierTypes.LanguageQualifierType | language qualifier type}.
|
|
52
|
+
* @param params - Optional {@link QualifierTypes.ILanguageQualifierTypeCreateParams | parameters} to use when creating
|
|
53
|
+
* the new instance.
|
|
54
|
+
* @returns `Success` with the new {@link QualifierTypes.LanguageQualifierType | language qualifier type} if successful, `Failure`
|
|
55
|
+
* otherwise.
|
|
56
|
+
*/
|
|
57
|
+
static create(params) {
|
|
58
|
+
/* c8 ignore next 1 - coverage seems to intermittently miss the branch even though it's tested */
|
|
59
|
+
params = params !== null && params !== void 0 ? params : {};
|
|
60
|
+
return (0, ts_utils_1.captureResult)(() => new LanguageQualifierType(params));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* {@inheritdoc QualifierTypes.IQualifierType.isValidConditionValue}
|
|
64
|
+
*/
|
|
65
|
+
isValidConditionValue(value) {
|
|
66
|
+
return ts_bcp47_1.Bcp47.tag(value).isSuccess();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Matches a single language condition against a single language context value using
|
|
70
|
+
* {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-bcp47#tag-matching | similarity matching}.
|
|
71
|
+
* @param condition - The language condition value to match.
|
|
72
|
+
* @param context - The language context value to match against.
|
|
73
|
+
* @param operator - The operator to use for the match. Must be 'matches'.
|
|
74
|
+
* @returns - The match score, or `noMatch` if the match fails.
|
|
75
|
+
*/
|
|
76
|
+
_matchOne(condition, context, operator) {
|
|
77
|
+
if (operator === 'matches') {
|
|
78
|
+
const similarity = ts_bcp47_1.Bcp47.similarity(condition, context).orDefault(ts_bcp47_1.Bcp47.tagSimilarity.none);
|
|
79
|
+
if (similarity > 0.0 && common_1.Validate.isValidQualifierMatchScore(similarity)) {
|
|
80
|
+
return similarity;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return common_1.NoMatch;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.LanguageQualifierType = LanguageQualifierType;
|
|
87
|
+
//# sourceMappingURL=languageQualifierType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"languageQualifierType.js","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/languageQualifierType.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAsD;AACtD,4CAAsC;AACtC,sCAQmB;AACnB,mDAA4E;AAoB5E;;;;;GAKG;AACH,MAAa,qBAAsB,SAAQ,6BAAa;IACtD;;;;;OAKG;IACH,YAAsB,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAsC;QACzF,gBAAgB,GAAG,gBAAgB,KAAK,KAAK,CAAC;QAC9C,iGAAiG;QACjG,IAAI,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,UAAU,CAAC;QAC1B,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAE9F,KAAK,iBACH,IAAI;YACJ,gBAAgB,IACb,SAAS,EACZ,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,MAA2C;QAC9D,iGAAiG;QACjG,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;QACtB,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC;IAChE,CAAC;IAED;;OAEG;IACI,qBAAqB,CAAC,KAAa;QACxC,OAAO,gBAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;OAOG;IACO,SAAS,CACjB,SAAkC,EAClC,OAA8B,EAC9B,QAA2B;QAE3B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,UAAU,GAAG,gBAAK,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,gBAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC5F,IAAI,UAAU,GAAG,GAAG,IAAI,iBAAQ,CAAC,0BAA0B,CAAC,UAAU,CAAC,EAAE,CAAC;gBACxE,OAAO,UAAU,CAAC;YACpB,CAAC;QACH,CAAC;QACD,OAAO,gBAAO,CAAC;IACjB,CAAC;CACF;AA7DD,sDA6DC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult } from '@fgv/ts-utils';\nimport { Bcp47 } from '@fgv/ts-bcp47';\nimport {\n ConditionOperator,\n Convert,\n NoMatch,\n QualifierConditionValue,\n QualifierContextValue,\n QualifierMatchScore,\n Validate\n} from '../common';\nimport { IQualifierTypeCreateParams, QualifierType } from './qualifierType';\n\n/**\n * Interface defining the parameters that can be used to create a new\n * {@link QualifierTypes.LanguageQualifierType | LanguageQualifierType}.\n * @public\n */\nexport interface ILanguageQualifierTypeCreateParams extends Partial<IQualifierTypeCreateParams> {\n /**\n * Optional name for the qualifier type. Defaults to 'language'.\n */\n name?: string;\n\n /**\n * Optional flag indicating whether the context can be a list of values.\n * Defaults to `true`.\n */\n allowContextList?: boolean;\n}\n\n/**\n * {@link QualifierTypes.QualifierType | Qualifier type} which matches BCP-47 language tags applying\n * {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-bcp47#tag-matching | similarity matching}.\n * Accepts a list of language tags in the context by default.\n * @public\n */\nexport class LanguageQualifierType extends QualifierType {\n /**\n * Creates a new instance of a {@link QualifierTypes.LanguageQualifierType | language qualifier type}.\n * @param name - Optional name for the qualifier type. Defaults to 'language'.\n * @param allowContextList - Optional flag indicating whether the context can be a list of values. Defaults to `true`.\n * @public\n */\n protected constructor({ name, allowContextList, index }: ILanguageQualifierTypeCreateParams) {\n allowContextList = allowContextList !== false;\n /* c8 ignore next 2 - coverage intermittently drops these two lines even though they're tested */\n name = name ?? 'language';\n const validated = index ? { index: Convert.qualifierTypeIndex.convert(index).orThrow() } : {};\n\n super({\n name,\n allowContextList,\n ...validated\n });\n }\n\n /**\n * Creates a new instance of a {@link QualifierTypes.LanguageQualifierType | language qualifier type}.\n * @param params - Optional {@link QualifierTypes.ILanguageQualifierTypeCreateParams | parameters} to use when creating\n * the new instance.\n * @returns `Success` with the new {@link QualifierTypes.LanguageQualifierType | language qualifier type} if successful, `Failure`\n * otherwise.\n */\n public static create(params?: ILanguageQualifierTypeCreateParams): Result<LanguageQualifierType> {\n /* c8 ignore next 1 - coverage seems to intermittently miss the branch even though it's tested */\n params = params ?? {};\n return captureResult(() => new LanguageQualifierType(params));\n }\n\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.isValidConditionValue}\n */\n public isValidConditionValue(value: string): value is QualifierConditionValue {\n return Bcp47.tag(value).isSuccess();\n }\n\n /**\n * Matches a single language condition against a single language context value using\n * {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-bcp47#tag-matching | similarity matching}.\n * @param condition - The language condition value to match.\n * @param context - The language context value to match against.\n * @param operator - The operator to use for the match. Must be 'matches'.\n * @returns - The match score, or `noMatch` if the match fails.\n */\n protected _matchOne(\n condition: QualifierConditionValue,\n context: QualifierContextValue,\n operator: ConditionOperator\n ): QualifierMatchScore {\n if (operator === 'matches') {\n const similarity = Bcp47.similarity(condition, context).orDefault(Bcp47.tagSimilarity.none);\n if (similarity > 0.0 && Validate.isValidQualifierMatchScore(similarity)) {\n return similarity;\n }\n }\n return NoMatch;\n }\n}\n"]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { ConditionOperator, QualifierConditionValue, QualifierContextValue, QualifierMatchScore } from '../common';
|
|
3
|
+
import { QualifierType } from './qualifierType';
|
|
4
|
+
/**
|
|
5
|
+
* Interface defining the parameters that can be used to create a new
|
|
6
|
+
* {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ILiteralQualifierTypeCreateParams {
|
|
10
|
+
/**
|
|
11
|
+
* Optional name for the qualifier type. Defaults to 'literal'.
|
|
12
|
+
*/
|
|
13
|
+
name?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional flag indicating whether the context can be a list of values.
|
|
16
|
+
* Defaults to `true`.
|
|
17
|
+
*/
|
|
18
|
+
allowContextList?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Optional flag indicating whether the match should be case-sensitive. Defaults to false.
|
|
21
|
+
*/
|
|
22
|
+
caseSensitive?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Optional array of enumerated values to further constrain the type. Defaults to no
|
|
25
|
+
* constraint.
|
|
26
|
+
*/
|
|
27
|
+
enumeratedValues?: ReadonlyArray<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Global index for this qualifier type.
|
|
30
|
+
*/
|
|
31
|
+
index?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A {@link QualifierTypes.QualifierType | qualifier} that matches a literal value., optionally case-sensitive
|
|
35
|
+
* or matching against an ordered list of values at runtime.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export declare class LiteralQualifierType extends QualifierType {
|
|
39
|
+
/**
|
|
40
|
+
* Indicates whether the qualifier match is case-sensitive.
|
|
41
|
+
*/
|
|
42
|
+
readonly caseSensitive: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Optional array of enumerated values to further constrain the type.
|
|
45
|
+
*/
|
|
46
|
+
readonly enumeratedValues?: ReadonlyArray<QualifierConditionValue>;
|
|
47
|
+
/**
|
|
48
|
+
* Constructs a new {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}.
|
|
49
|
+
* @param name - Optional name for the qualifier type. Defaults to 'literal'.
|
|
50
|
+
* @param caseSensitive - Optional flag indicating whether the match should be case-sensitive. Defaults to false.
|
|
51
|
+
* @param allowContextList - Optional flag indicating whether the context can be a list of values. Defaults to false.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
protected constructor({ name, caseSensitive, allowContextList, enumeratedValues, index }: ILiteralQualifierTypeCreateParams);
|
|
55
|
+
/**
|
|
56
|
+
* Determines whether a value is a valid condition value for a literal qualifier. The
|
|
57
|
+
* {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType} accepts
|
|
58
|
+
* any identifier as a valid condition value.
|
|
59
|
+
* @param value - The value to validate.
|
|
60
|
+
* @returns `true` if the value is a valid condition value, `false` otherwise.
|
|
61
|
+
*/
|
|
62
|
+
isValidConditionValue(value: string): value is QualifierConditionValue;
|
|
63
|
+
/**
|
|
64
|
+
* {@inheritdoc QualifierTypes.QualifierType._matchOne}
|
|
65
|
+
*/
|
|
66
|
+
protected _matchOne(condition: QualifierConditionValue, context: QualifierContextValue, operator: ConditionOperator): QualifierMatchScore;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}.
|
|
69
|
+
* @param params - Optional {@link QualifierTypes.ILiteralQualifierTypeCreateParams | parameters}
|
|
70
|
+
* to use when creating the new instance.
|
|
71
|
+
* @returns `Success` with the new {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}
|
|
72
|
+
* if successful, `Failure` with an error message otherwise.
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
static create(params?: ILiteralQualifierTypeCreateParams): Result<LiteralQualifierType>;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if the given value is a valid literal condition value.
|
|
78
|
+
* @param from - The value to validate.
|
|
79
|
+
* @returns `true` if the value is a valid literal condition value, otherwise `false`.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
static isValidLiteralConditionValue(from: string): from is QualifierConditionValue;
|
|
83
|
+
/**
|
|
84
|
+
* Converts a string to a {@link QualifierConditionValue | literal condition value}.
|
|
85
|
+
* @param from - The string to convert.
|
|
86
|
+
* @returns `Success` with the converted value if valid, or `Failure` with an error message
|
|
87
|
+
* if not.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
static toLiteralConditionValue(from: string): Result<QualifierConditionValue>;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=literalQualifierType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literalQualifierType.d.ts","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/literalQualifierType.ts"],"names":[],"mappings":"AAsBA,OAAO,EAA6B,MAAM,EAAiB,MAAM,eAAe,CAAC;AACjF,OAAO,EACL,iBAAiB,EAIjB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EAEpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,iCAAiC;IAChD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAEzC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;IACrD;;OAEG;IACH,SAAgB,aAAa,EAAE,OAAO,CAAC;IAEvC;;OAEG;IACH,SAAgB,gBAAgB,CAAC,EAAE,aAAa,CAAC,uBAAuB,CAAC,CAAC;IAE1E;;;;;;OAMG;IACH,SAAS,aAAa,EACpB,IAAI,EACJ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,EACN,EAAE,iCAAiC;IAapC;;;;;;OAMG;IACI,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,uBAAuB;IAU7E;;OAEG;IACH,SAAS,CAAC,SAAS,CACjB,SAAS,EAAE,uBAAuB,EAClC,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,EAAE,iBAAiB,GAC1B,mBAAmB;IAQtB;;;;;;;OAOG;WACW,MAAM,CAAC,MAAM,CAAC,EAAE,iCAAiC,GAAG,MAAM,CAAC,oBAAoB,CAAC;IAI9F;;;;;OAKG;WACW,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,uBAAuB;IAIzF;;;;;;OAMG;WACW,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,uBAAuB,CAAC;CAKrF"}
|