inferred-types 0.36.1 → 0.36.4
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/dist/index.d.ts
CHANGED
|
@@ -2146,7 +2146,7 @@ type StripLeading<T extends string, U extends string> = IfLiteral<T, string exte
|
|
|
2146
2146
|
* `EnsureStarting<T>`, and `StripStarting<T>` to further shape
|
|
2147
2147
|
* the type.
|
|
2148
2148
|
*/
|
|
2149
|
-
type PathJoin<T extends string, U extends string | readonly string[]> = U extends readonly string[] ? PathMultiJoin<PathJoin<T, "">, [...U]> : U extends string ? IfLiteral<T, IfLiteral<U, `${StripTrailing<T, "/">}/${StripLeading<U, "/">}`, `${StripTrailing<T, "/">}/${string}`>, IfLiteral<U, `${string}${U}`, string>> : never;
|
|
2149
|
+
type PathJoin<T extends string, U extends string | readonly string[]> = [] extends U ? T : U extends readonly string[] ? PathMultiJoin<PathJoin<T, "">, [...U]> : U extends string ? IfLiteral<T, IfLiteral<U, `${StripTrailing<T, "/">}/${StripLeading<U, "/">}`, `${StripTrailing<T, "/">}/${string}`>, IfLiteral<U, `${string}${U}`, string>> : never;
|
|
2150
2150
|
type PathMultiJoin<TProcessed extends string, TRemaining extends readonly string[]> = [] extends TRemaining ? TProcessed : PathMultiJoin<PathJoin<TProcessed, First<TRemaining>>, AfterFirst<TRemaining>>;
|
|
2151
2151
|
|
|
2152
2152
|
type Consonant = "b" | "c" | "d" | "f" | "g" | "h" | "j" | "k" | "l" | "m" | "n" | "p" | "q" | "r" | "s" | "t" | "v" | "w" | "x" | "z" | "y";
|
|
@@ -2221,6 +2221,19 @@ type UrlBuilder = (<P extends NetworkProtocol, D extends DomainName, B extends R
|
|
|
2221
2221
|
*/
|
|
2222
2222
|
declare function ensureLeading<T extends string, U extends string>(content: T, ensure: U): EnsureLeading<T, U>;
|
|
2223
2223
|
|
|
2224
|
+
/**
|
|
2225
|
+
* **pathJoin**`<T,U>(begin, ...rest)`
|
|
2226
|
+
*
|
|
2227
|
+
* Run time utility which joins two strings together with
|
|
2228
|
+
* the intent to have them be divided by a Posix `/` character
|
|
2229
|
+
* appropriate for Unix file paths and URLs.
|
|
2230
|
+
*
|
|
2231
|
+
* **note:** to support more than two paths being joined there
|
|
2232
|
+
* is now the ability to add a tuple of paths into the _rest_
|
|
2233
|
+
* parameter
|
|
2234
|
+
*/
|
|
2235
|
+
declare function pathJoin<T extends string, U extends readonly string[]>(begin: T, ...rest: U): PathJoin<T, U>;
|
|
2236
|
+
|
|
2224
2237
|
/**
|
|
2225
2238
|
* **Suggest**
|
|
2226
2239
|
*
|
|
@@ -2729,4 +2742,4 @@ type PureFluentApi<TApi extends Record<string, (...args: any[]) => PureFluentApi
|
|
|
2729
2742
|
[P in keyof TApi]: (...args: Parameters<TApi[P]>) => PureFluentApi<Omit<TApi, TExclude>>;
|
|
2730
2743
|
};
|
|
2731
2744
|
|
|
2732
|
-
export { AfterFirst, AllCaps, Alpha, AlphaNumeric, AnyFunction, Api, ApiFunction, ApiValue, AppendToDictionary, AppendToObject, ArrConcat, Array$1 as Array, ArrayConverter, AsArray, AsFinalizedConfig, AssertExtends, Box, BoxValue, BoxedFnParams, BoxedReturn, Bracket, Break, CamelCase, CapitalizeWords, Cardinality, Cardinality0, Cardinality1, CardinalityExplicit, CardinalityFilter0, CardinalityFilter1, CardinalityIn, CardinalityInput, CardinalityNode, CardinalityOut, CardinalityTuple, ClosingBracket, Condition, ConditionFilter, Configurator, ConfiguredMap, Constructor, Contains, DEFAULT_MANY_TO_ONE_MAPPING, DEFAULT_ONE_TO_MANY_MAPPING, DEFAULT_ONE_TO_ONE_MAPPING, DashToSnake, DashUppercase, Dasherize, DecomposeMapConfig, DefaultManyToOneMapping, DefaultOneToManyMapping, DefaultOneToOneMapping, DefinePropertiesApi, DictArrApi, DictArray, DictArrayFilterCallback, DictArrayKv, DictChangeValue, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DictionaryWithoutValue, DomainName, DynamicRule, DynamicRuleSet, Email, EndsWith, EnsureLeading, EnsureTrailing, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, Extends, FilterContains, FilterDefn, FilterEnds, FilterEquals, FilterFn, FilterGreaterThan, FilterIs, FilterLessThan, FilterNotEqual, FilterStarts, FilterTuple, FinalReturn, FinalizedMapConfig, First, FirstKey, FirstKeyValue, FirstOfEach, FirstOrUndefined, FirstString, FluentConfigurator, FluentFunction, FnShape, FromDictArray, FullyQualifiedUrl, FunctionType, GeneralDictionary, Get, HasParameters, HasUppercase, HybridFunction, IConfigurator, IFluentConfigurator, If, IfArray, IfBooleanLiteral, IfEndsWith, IfExtends, IfExtendsThen, IfFalse, IfLiteral, IfNumericLiteral, IfObject, IfOptionalLiteral, IfReadonlyArray, IfScalar, IfStartsWith, IfStringLiteral, IfTrue, IfUndefined, Include, Includes, IntersectingKeys, Ipv4, IsArray, IsBoolean, IsBooleanLiteral, IsCapitalized, IsEqual, IsFalse, IsFunction, IsLiteral, IsNull, IsNumber, IsNumericLiteral, IsObject, IsOptionalLiteral, IsReadonlyArray, IsScalar, IsStringLiteral, IsTrue, IsUndefined, KebabCase, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LogicFunction, LogicalCombinator, LowerAllCaps, LowerAlpha, ManyToMany, ManyToOne, ManyToZero, MapCard, MapCardinality, MapCardinalityFrom, MapCardinalityIllustrated, MapConfig, MapFn, MapFnInput, MapFnOutput, MapIR, MapInput, MapInputFrom, MapOR, MapOutput, MapOutputFrom, MapTo, Mapper, MapperApi, MaybeFalse, MaybeTrue, Mutable, MutableProps, NarrowBox, Narrowable, NarrowlyContains, NetworkProtocol, NonAlpha, NonNumericKeys, NonStringKeys, Not, NotEqual, NotFilter, Numeric, NumericFilter, NumericKeys, NumericString, ObjectType, OneToMany, OneToOne, OneToZero, Opaque, OpeningBracket, OptRequired, OptionalKeys, OptionalProps, Or, Parenthesis, PascalCase, PathJoin, Pluralize, PrivateKey, PrivateKeys, PublicKeys, Punctuation, PureFluentApi, RelativeUrl, Replace, RequireProps, RequiredKeys, RequiredProps, Retain, RightWhitespace, RuleDefinition, RuntimeProp, RuntimeType, SameKeys, SecondOfEach, SimpleFunction, SimplifyObject, SnakeCase, SpecialCharacters, Split, StartsWith, StringDelimiter, StringFilter, StringKeys, StringLength, StripLeading, StripTrailing, Suggest, SuggestNumeric, ToFluent, Transformer, Trim, TrimLeft, TrimRight, TupleToUnion, Type, TypeApi, TypeDefault, TypeDefinition, TypeGuard, TypeOptions, Unbox, UndefinedArrayIsUnknown, UndefinedTreatment, UndefinedValue, UnionToIntersection, UnionToTuple, UniqueDictionary, UniqueForProp, Uniqueness, UnwrapNot, UpperAlpha, UrlBuilder, VariableName, Where, WhereNot, Whitespace, Widen, WithNumericKeys, WithStringKeys, WithValue, ZeroToMany, ZeroToOne, ZeroToZero, ZipCode, and, api, arrayToKeyLookup, arrayToObject, asArray, box, boxDictionaryValues, condition, createConverter, createFnWithProps, defineProperties, defineType, dictArr, dictToKv, dictionaryTransform, ensureLeading, ensureTrailing, entries, filter, filterDictArray, fnWithProps, groupBy, idLiteral, idTypeGuard, identity, ifArray, ifArrayPartial, ifBoolean, ifDefined, ifFalse, ifNull, ifNumber, ifObject, ifSameType, ifString, ifTrue, ifUndefined, isArray, isBoolean, isBox, isFalse, isFunction, isNotFilter, isNull, isNumber, isNumericFilter, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, literal, mapTo, mapToDict, mapToFn, mapValues, nameLiteral, not, or, readonlyFnWithProps, ruleSet, strArrayToDict, stripTrailing, type, typeApi, unbox, wide, withValue };
|
|
2745
|
+
export { AfterFirst, AllCaps, Alpha, AlphaNumeric, AnyFunction, Api, ApiFunction, ApiValue, AppendToDictionary, AppendToObject, ArrConcat, Array$1 as Array, ArrayConverter, AsArray, AsFinalizedConfig, AssertExtends, Box, BoxValue, BoxedFnParams, BoxedReturn, Bracket, Break, CamelCase, CapitalizeWords, Cardinality, Cardinality0, Cardinality1, CardinalityExplicit, CardinalityFilter0, CardinalityFilter1, CardinalityIn, CardinalityInput, CardinalityNode, CardinalityOut, CardinalityTuple, ClosingBracket, Condition, ConditionFilter, Configurator, ConfiguredMap, Constructor, Contains, DEFAULT_MANY_TO_ONE_MAPPING, DEFAULT_ONE_TO_MANY_MAPPING, DEFAULT_ONE_TO_ONE_MAPPING, DashToSnake, DashUppercase, Dasherize, DecomposeMapConfig, DefaultManyToOneMapping, DefaultOneToManyMapping, DefaultOneToOneMapping, DefinePropertiesApi, DictArrApi, DictArray, DictArrayFilterCallback, DictArrayKv, DictChangeValue, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DictionaryWithoutValue, DomainName, DynamicRule, DynamicRuleSet, Email, EndsWith, EnsureLeading, EnsureTrailing, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, Extends, FilterContains, FilterDefn, FilterEnds, FilterEquals, FilterFn, FilterGreaterThan, FilterIs, FilterLessThan, FilterNotEqual, FilterStarts, FilterTuple, FinalReturn, FinalizedMapConfig, First, FirstKey, FirstKeyValue, FirstOfEach, FirstOrUndefined, FirstString, FluentConfigurator, FluentFunction, FnShape, FromDictArray, FullyQualifiedUrl, FunctionType, GeneralDictionary, Get, HasParameters, HasUppercase, HybridFunction, IConfigurator, IFluentConfigurator, If, IfArray, IfBooleanLiteral, IfEndsWith, IfExtends, IfExtendsThen, IfFalse, IfLiteral, IfNumericLiteral, IfObject, IfOptionalLiteral, IfReadonlyArray, IfScalar, IfStartsWith, IfStringLiteral, IfTrue, IfUndefined, Include, Includes, IntersectingKeys, Ipv4, IsArray, IsBoolean, IsBooleanLiteral, IsCapitalized, IsEqual, IsFalse, IsFunction, IsLiteral, IsNull, IsNumber, IsNumericLiteral, IsObject, IsOptionalLiteral, IsReadonlyArray, IsScalar, IsStringLiteral, IsTrue, IsUndefined, KebabCase, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LogicFunction, LogicalCombinator, LowerAllCaps, LowerAlpha, ManyToMany, ManyToOne, ManyToZero, MapCard, MapCardinality, MapCardinalityFrom, MapCardinalityIllustrated, MapConfig, MapFn, MapFnInput, MapFnOutput, MapIR, MapInput, MapInputFrom, MapOR, MapOutput, MapOutputFrom, MapTo, Mapper, MapperApi, MaybeFalse, MaybeTrue, Mutable, MutableProps, NarrowBox, Narrowable, NarrowlyContains, NetworkProtocol, NonAlpha, NonNumericKeys, NonStringKeys, Not, NotEqual, NotFilter, Numeric, NumericFilter, NumericKeys, NumericString, ObjectType, OneToMany, OneToOne, OneToZero, Opaque, OpeningBracket, OptRequired, OptionalKeys, OptionalProps, Or, Parenthesis, PascalCase, PathJoin, Pluralize, PrivateKey, PrivateKeys, PublicKeys, Punctuation, PureFluentApi, RelativeUrl, Replace, RequireProps, RequiredKeys, RequiredProps, Retain, RightWhitespace, RuleDefinition, RuntimeProp, RuntimeType, SameKeys, SecondOfEach, SimpleFunction, SimplifyObject, SnakeCase, SpecialCharacters, Split, StartsWith, StringDelimiter, StringFilter, StringKeys, StringLength, StripLeading, StripTrailing, Suggest, SuggestNumeric, ToFluent, Transformer, Trim, TrimLeft, TrimRight, TupleToUnion, Type, TypeApi, TypeDefault, TypeDefinition, TypeGuard, TypeOptions, Unbox, UndefinedArrayIsUnknown, UndefinedTreatment, UndefinedValue, UnionToIntersection, UnionToTuple, UniqueDictionary, UniqueForProp, Uniqueness, UnwrapNot, UpperAlpha, UrlBuilder, VariableName, Where, WhereNot, Whitespace, Widen, WithNumericKeys, WithStringKeys, WithValue, ZeroToMany, ZeroToOne, ZeroToZero, ZipCode, and, api, arrayToKeyLookup, arrayToObject, asArray, box, boxDictionaryValues, condition, createConverter, createFnWithProps, defineProperties, defineType, dictArr, dictToKv, dictionaryTransform, ensureLeading, ensureTrailing, entries, filter, filterDictArray, fnWithProps, groupBy, idLiteral, idTypeGuard, identity, ifArray, ifArrayPartial, ifBoolean, ifDefined, ifFalse, ifNull, ifNumber, ifObject, ifSameType, ifString, ifTrue, ifUndefined, isArray, isBoolean, isBox, isFalse, isFunction, isNotFilter, isNull, isNumber, isNumericFilter, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, literal, mapTo, mapToDict, mapToFn, mapValues, nameLiteral, not, or, pathJoin, readonlyFnWithProps, ruleSet, strArrayToDict, stripTrailing, type, typeApi, unbox, wide, withValue };
|
package/dist/index.mjs
CHANGED
|
@@ -754,6 +754,21 @@ function ensureTrailing(content, ensure) {
|
|
|
754
754
|
function ensureLeading(content, ensure) {
|
|
755
755
|
return content.startsWith(ensure) ? content : `${ensure}${content}`;
|
|
756
756
|
}
|
|
757
|
+
|
|
758
|
+
// src/runtime/literals/stripLeading.ts
|
|
759
|
+
function stripLeading(content, strip) {
|
|
760
|
+
const re = new RegExp(`^${strip}(.*)`);
|
|
761
|
+
return content.startsWith(strip) ? content.replace(re, "$1") : content;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/runtime/literals/pathJoin.ts
|
|
765
|
+
function pathJoin(begin, ...rest) {
|
|
766
|
+
const start = rest.length > 0 ? ensureTrailing(begin, "/") : begin;
|
|
767
|
+
const end = rest.length > 0 ? ensureLeading(rest.slice(-1)[0], "/") : "";
|
|
768
|
+
const middle = rest.length > 1 ? rest.slice(0, rest.length - 1).map((i) => stripLeading(stripTrailing(i, "/"), '"')) : [];
|
|
769
|
+
const midString = stripTrailing(stripLeading(middle.join("/"), "/"), "/");
|
|
770
|
+
return rest.length > 1 ? `${start}${midString}${end}` : `${start}${stripLeading(end, "/")}`;
|
|
771
|
+
}
|
|
757
772
|
export {
|
|
758
773
|
Configurator,
|
|
759
774
|
DEFAULT_MANY_TO_ONE_MAPPING,
|
|
@@ -826,6 +841,7 @@ export {
|
|
|
826
841
|
nameLiteral,
|
|
827
842
|
not,
|
|
828
843
|
or,
|
|
844
|
+
pathJoin,
|
|
829
845
|
readonlyFnWithProps,
|
|
830
846
|
ruleSet,
|
|
831
847
|
strArrayToDict,
|
package/package.json
CHANGED
|
@@ -19,11 +19,12 @@ export function pathJoin<T extends string, U extends readonly string[]>(
|
|
|
19
19
|
begin: T,
|
|
20
20
|
...rest: U
|
|
21
21
|
): PathJoin<T, U> {
|
|
22
|
-
const start = ensureTrailing(begin, "/");
|
|
23
|
-
const end = ensureLeading(rest.slice(-1)[0], "/");
|
|
24
|
-
const middle =
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const start = rest.length > 0 ? ensureTrailing(begin, "/") : begin;
|
|
23
|
+
const end = rest.length > 0 ? ensureLeading(rest.slice(-1)[0], "/") : "";
|
|
24
|
+
const middle =
|
|
25
|
+
rest.length > 1
|
|
26
|
+
? rest.slice(0, rest.length - 1).map((i) => stripLeading(stripTrailing(i, "/"), '"'))
|
|
27
|
+
: [];
|
|
27
28
|
const midString = stripTrailing(stripLeading(middle.join("/"), "/"), "/");
|
|
28
29
|
|
|
29
30
|
return (
|
|
@@ -21,7 +21,9 @@ export type PathJoin<
|
|
|
21
21
|
T extends string,
|
|
22
22
|
// trailing string or strings
|
|
23
23
|
U extends string | readonly string[]
|
|
24
|
-
> =
|
|
24
|
+
> = [] extends U
|
|
25
|
+
? T
|
|
26
|
+
: U extends readonly string[]
|
|
25
27
|
? // eslint-disable-next-line no-use-before-define
|
|
26
28
|
PathMultiJoin<PathJoin<T, "">, [...U]>
|
|
27
29
|
: U extends string
|
|
@@ -91,4 +91,21 @@ describe("pathJoin() runtime util", () => {
|
|
|
91
91
|
expect(t3).toBe("/foo/bar/baz");
|
|
92
92
|
expect(t4).toBe("foo/bar/baz/");
|
|
93
93
|
});
|
|
94
|
+
|
|
95
|
+
it("singular value", () => {
|
|
96
|
+
const t1 = pathJoin("foo");
|
|
97
|
+
const t2 = pathJoin("foo/");
|
|
98
|
+
|
|
99
|
+
// runtime
|
|
100
|
+
expect(t1).toBe("foo");
|
|
101
|
+
expect(t2).toBe("foo/");
|
|
102
|
+
|
|
103
|
+
// design time
|
|
104
|
+
type cases = [
|
|
105
|
+
//
|
|
106
|
+
Expect<Equal<typeof t1, "foo">>,
|
|
107
|
+
Expect<Equal<typeof t2, "foo/">>
|
|
108
|
+
];
|
|
109
|
+
const cases: cases = [true, true];
|
|
110
|
+
});
|
|
94
111
|
});
|