@qualified/ccc-files
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

@qualified/ccc-files

Provides a function to map ClassicCodeChallenge fields to files.

type FileWithSource = {
  path: string;
  contents: string;
  source: "solution" | "tests" | "preloaded" | "generated";
};

type ClassicCodeChallenge = {
  preloaded?: string;
  solution: string;
  tests: string;
  language: string;
  languageVersion?: string;
  testFramework: string;
  preset?: string;
};

type Options = {
  /**
   * For paths based on the field value, fall back to a predefined path instead of
   * throwing an error on invalid value.
   */
  fallback?: boolean;
};

const toFiles: (ccc: ClassicCodeChallenge, opts?: Options) => FileWithSource[];

Supported Languages

  • C#
  • Dart
  • Java
  • JavaScript
  • Python
  • Ruby
  • TypeScript

Usage

import { toFiles } from "@qualified/ccc-files";

const preloaded = `
package example;

public class Preloaded {}
`;
const solution = `
package example;

public class Example {}
`;
const tests = `
package example;

class ExampleTests {}
`;

toFiles({
  preloaded,
  solution,
  tests,
  language: "java",
  languageVersion: "17",
  testFramework: "junit",
});
[
  {
    path: "src/test/java/example/ExampleTests.java",
    contents: "...",
    source: "tests",
  },
  {
    path: "src/main/java/example/Example.java",
    contents: "...",
    source: "solution",
  },
  {
    path: "src/main/java/example/Preloaded.java",
    contents: "...",
    source: "preloaded",
  },
];

Readme

Keywords

none

Package Sidebar

Install

npm i @qualified/ccc-files

Weekly Downloads

42

Version

0.2.1

License

MIT

Unpacked Size

39 kB

Total Files

84

Last publish

Collaborators

  • ckorze
  • greg.gorlen
  • kazk
  • jhoffner