= Props extends undefined
5 | ? [] | (EmptyIfUndef extends true ? never : [props: undefined])
6 | : undefined extends Props
7 | ? [props?: Props]
8 | : [props: Props];
9 |
10 | export type BasePropsOrMapper = B extends undefined
11 | ? []
12 | : undefined extends B
13 | ? P extends undefined
14 | ? [baseProps?: B]
15 | : [mapToBase?: (...rest: Props
) => B] | [baseProps?: B]
16 | : [mapToBase: (...rest: Props
) => B] | [baseProps: B];
17 | }
18 |
--------------------------------------------------------------------------------
/src/util/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./in-rest";
2 | export * from "./molecules";
3 | export * from "./recombine-tagged-template-args";
4 |
--------------------------------------------------------------------------------
/src/util/molecules.ts:
--------------------------------------------------------------------------------
1 | export type AnyRec = Record;
2 | export namespace AnyRec {
3 | export type Or = AnyRec | O;
4 | export namespace Or {
5 | export type Undef = Or;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/util/recombine-tagged-template-args.test.ts:
--------------------------------------------------------------------------------
1 | import {recombineTaggedTemplateArgs} from "./recombine-tagged-template-args";
2 |
3 | const A = "A";
4 | const B = "8";
5 | const C = "Three";
6 |
7 | function argumentsOf(quasis: TemplateStringsArray, ...rest: string[]): [TemplateStringsArray, ...string[]] {
8 | return [quasis, ...rest];
9 | }
10 |
11 | describe("Recombine Tagged Template Args", () => {
12 | it("Without Quasis", () => {
13 | expect.assertions(1);
14 | const withoutQuasis = argumentsOf`Nice kicks man... those Air Jordan Retros?`;
15 | expect(recombineTaggedTemplateArgs(...withoutQuasis)).toStrictEqual("Nice kicks man... those Air Jordan Retros?");
16 | });
17 |
18 | it("Starting With Quasis", () => {
19 | expect.assertions(1);
20 | const startingWithQuasis = argumentsOf`${A} good way to code is to just close your eyes & hope for the ${B}est.`;
21 | expect(recombineTaggedTemplateArgs(...startingWithQuasis)).toStrictEqual(
22 | `A good way to code is to just close your eyes & hope for the 8est.`,
23 | );
24 | });
25 |
26 | it("With Middle Quasis", () => {
27 | expect.assertions(1);
28 | const withMiddleQuasis = argumentsOf`The number "${B}", the letter "${A}", and the spelled-number "${C}"`;
29 | expect(recombineTaggedTemplateArgs(...withMiddleQuasis)).toStrictEqual(
30 | `The number "8", the letter "A", and the spelled-number "Three"`,
31 | );
32 | });
33 |
34 | it("Without Literal Quasis", () => {
35 | expect.assertions(1);
36 | const withLiteralQuasis = argumentsOf`Lorem ipsum ${"dolor"}...`;
37 | expect(recombineTaggedTemplateArgs(...withLiteralQuasis)).toStrictEqual("Lorem ipsum dolor...");
38 | });
39 | });
40 |
--------------------------------------------------------------------------------
/src/util/recombine-tagged-template-args.ts:
--------------------------------------------------------------------------------
1 | export function recombineTaggedTemplateArgs(quasis: TemplateStringsArray, ...rest: string[]): string {
2 | return quasis.reduce((acc, e, i) => {
3 | return `${acc}${e}${rest[i] || ""}`;
4 | }, "");
5 | }
6 |
--------------------------------------------------------------------------------
/tsconfig.base.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "alwaysStrict": true,
4 | "declaration": true,
5 | "downlevelIteration": true,
6 | "esModuleInterop": true,
7 | "forceConsistentCasingInFileNames": true,
8 | "inlineSourceMap": true,
9 | "lib": ["DOM", "DOM.Iterable", "ESNext"],
10 | "module": "CommonJS",
11 | "moduleResolution": "node",
12 | "noEmitOnError": true,
13 | "noFallthroughCasesInSwitch": true,
14 | "noImplicitAny": true,
15 | "noImplicitThis": true,
16 | "noImplicitReturns": true,
17 | "noUncheckedIndexedAccess": true,
18 | "noUnusedLocals": true,
19 | "noUnusedParameters": true,
20 | "resolveJsonModule": true,
21 | "strict": true,
22 | "strictBindCallApply": true,
23 | "strictFunctionTypes": true,
24 | "strictNullChecks": true,
25 | "strictPropertyInitialization": true,
26 | "stripInternal": true,
27 | "target": "ES2018",
28 | "typeRoots": ["node_modules/@types"],
29 | "useDefineForClassFields": true
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "outDir": "cjs"
4 | },
5 | "exclude": ["**/*.test.ts", "**/tests/**/*", "example", "node_modules"],
6 | "extends": "./tsconfig.base.json",
7 | "include": ["src"]
8 | }
9 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": true,
3 | "exclude": ["node_modules"],
4 | "extends": "./tsconfig.base.json",
5 | "include": ["example", "src"]
6 | }
7 |
--------------------------------------------------------------------------------