diff --git a/.codecov.yml b/.codecov.yml
index 3b26ad1..e8e41a8 100644
--- a/.codecov.yml
+++ b/.codecov.yml
@@ -1,28 +1,69 @@
# codecov:
# notify:
# require_ci_to_pass: yes
-
coverage:
status:
project:
- default:
- target: 90%
- color:
+ utilities:
target: auto
threshold: 7%
base: auto
if_ci_failed: success
flags:
- color
+ - config
+ - log
+ - watch
+ common:
+ target: 40%
+ threshold: 10%
+ if_ci_failed: error
+ flags:
+ - common
precision: 2
round: down
range: '70...100'
-
+# flag_management:
+# # this section will govern all default rules of Flags
+# default_rules:
+# carryforward: true
+# ignore:
+# - "**/*_test.ts"
+# - "**/*_test.tsx"
+# paths:
+# - "src/**"
+# statuses:
+# - name_prefix: default_project
+# type: project
+# target: auto
+# threshold: 1%
+# - name_prefix: default_patch
+# type: patch
+# target: percent
+# threshold: 80%
+ignore:
+ - "**/*_test.ts"
+ - "**/*_test.tsx"
flags:
color:
paths:
- - color/src/**
- - '!color/src/**_test.ts'
+ - src/color/
+ common:
+ paths:
+ - src/common/
+ config:
+ paths:
+ - src/config/
+ log:
+ paths:
+ - src/log/
+ watch:
+ paths:
+ - src/watch/
+ # test:
+ # paths:
+ # - test/
+
parsers:
gcov:
branch_detection:
diff --git a/.docker/Dockerfile b/.docker/Dockerfile
new file mode 100644
index 0000000..cb26741
--- /dev/null
+++ b/.docker/Dockerfile
@@ -0,0 +1,17 @@
+FROM alpine:3.13.2 AS organizer
+
+# Installation files
+WORKDIR /out/usr/src/install
+COPY src src
+COPY test test
+COPY mod.ts .
+COPY import_map.json .
+COPY trailmix.config.ts .
+COPY trilom.config.ts .
+
+FROM hayd/alpine-deno:1.8.1 AS runner
+COPY --from=organizer /out /
+
+# Install
+WORKDIR /usr/src/install
+ENV PATH "/root/.deno/bin:$PATH"
diff --git a/.eslintrc.js b/.eslintrc.js
deleted file mode 100644
index 757a727..0000000
--- a/.eslintrc.js
+++ /dev/null
@@ -1,12 +0,0 @@
-module.exports = {
- extends: ['alloy', 'alloy/react', 'alloy/typescript'],
- env: {
- node: true,
- },
- globals: {
- Deno: false,
- },
- rules: {
- '@typescript-eslint/consistent-type-imports': 'error',
- },
-};
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5ae800e..634ae46 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,15 +25,16 @@ jobs:
- name: Run tests (ubuntu)
if: matrix.os == 'ubuntu-latest'
- run: yarn test-coverage
+ run: deno test --unstable --allow-write --allow-read --allow-env --import-map=import_map.json --coverage=./coverage/output
- name: Run tests (win/mac)
if: matrix.os != 'ubuntu-latest'
- run: deno test --unstable --allow-net --import-map=import_map.json
+ run: deno test --unstable --allow-write --allow-read --allow-env --import-map=import_map.json
+
- name: Generate codecov report
if: matrix.os == 'ubuntu-latest'
- run: yarn coverage
+ run: deno coverage --unstable ./coverage --lcov > ./coverage/lcov.info
- name: Push codecov report
if: matrix.os == 'ubuntu-latest'
- run: bash <(curl -s https://codecov.io/bash)
+ run: bash <(curl -s https://codecov.io/bash) -F color,common,config -c
diff --git a/.prettierignore b/.prettierignore
deleted file mode 100644
index 313853f..0000000
--- a/.prettierignore
+++ /dev/null
@@ -1,16 +0,0 @@
-*.svg
-*.png
-*.ico
-*.sh
-*.pxd
-
-.github/ISSUE_TEMPLATE
-.dockerignore
-.DS_Store
-.eslintignore
-.gitattributes
-.gitignore
-.prettierignore
-Dockerfile
-LICENSE
-
diff --git a/.prettierrc.js b/.prettierrc.js
deleted file mode 100644
index 0f0c897..0000000
--- a/.prettierrc.js
+++ /dev/null
@@ -1,38 +0,0 @@
-// .prettierrc.js
-module.exports = {
- // max 120 characters per line
- printWidth: 120,
- // use 2 spaces for indentation
- tabWidth: 2,
- // use spaces instead of indentations
- useTabs: false,
- // semicolon at the end of the line
- semi: true,
- // use single quotes
- singleQuote: true,
- // object's key is quoted only when necessary
- quoteProps: 'as-needed',
- // use double quotes instead of single quotes in jsx
- jsxSingleQuote: false,
- // no comma at the end
- trailingComma: 'all',
- // spaces are required at the beginning and end of the braces
- bracketSpacing: true,
- // end tag of jsx need to wrap
- jsxBracketSameLine: false,
- // brackets are required for arrow function parameter, even when there is only one parameter
- arrowParens: 'always',
- // format the entire contents of the file
- rangeStart: 0,
- rangeEnd: Infinity,
- // no need to write the beginning @prettier of the file
- requirePragma: false,
- // No need to automatically insert @prettier at the beginning of the file
- insertPragma: false,
- // use default break criteria
- proseWrap: 'preserve',
- // decide whether to break the html according to the display style
- htmlWhitespaceSensitivity: 'css',
- // lf for newline
- endOfLine: 'lf',
-};
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 0660fb9..46bacaf 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -5,12 +5,21 @@
"version": "0.2.0",
"configurations": [
{
- "name": "test: test",
+ "name": "Launch",
+ "type": "node",
"request": "launch",
- "runtimeExecutable": "yarn",
- "runtimeArgs": ["test-inspect"],
- "attachSimplePort": 9229,
- "type": "pwa-node",
+ "cwd": "${workspaceFolder}",
+ "runtimeExecutable": "deno",
+ "runtimeArgs": [
+ "test",
+ "--inspect=127.0.0.1:9229",
+ "--unstable",
+ "--allow-read",
+ "--allow-write",
+ "--allow-env",
+ "--import-map=import_map.json"
+ ],
+ "port": 9229,
"outputCapture": "std"
}
]
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 2c523f5..d510da5 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,6 +1,8 @@
{
"files.eol": "\n",
+ // deno
"deno.enable": true,
+ "deno.lint": true,
"deno.codeLens.implementations": true,
"deno.codeLens.references": true,
"deno.codeLens.referencesAllFunctions": true,
@@ -9,16 +11,15 @@
"deno.suggest.completeFunctionCalls": true,
"deno.suggest.paths": true,
"deno.importMap": "./import_map.json",
+ // coverage
"coverage-gutters.lcovname": "./coverage/lcov.info",
"coverage-gutters.showGutterCoverage": true,
+ // ui
"editor.snippetSuggestions": "inline",
"typescript.suggest.completeJSDocs": true,
+ // formatter
"editor.tabSize": 2,
"editor.formatOnSave": true,
- "editor.defaultFormatter": "esbenp.prettier-vscode",
- "editor.codeActionsOnSave": {
- "source.fixAll.eslint": true,
- "source.organizeImports.eslint": true
- },
- "typescript.tsdk": "node_modules/typescript/lib"
+ "editor.defaultFormatter": "denoland.vscode-deno",
+ "debug.javascript.unmapMissingSources": true
}
diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md
index 84d26ef..bba9727 100644
--- a/CONTRIBUTE.md
+++ b/CONTRIBUTE.md
@@ -1,11 +1,9 @@
# Contribute
+
```bash
-# ensure you have extensions installed
+# docker should be installed
+docker build -t trailmix -f .docker/Dockerfile .
-# setup env
-yarn
-# test all projects
-yarn test
-# test one project
-yarn test-one color/*_test.ts
-```
\ No newline at end of file
+# now run tests
+docker run trailmix deno test --unstable --allow-write --allow-read --allow-env --import-map=import_map.json
+```
diff --git a/README.md b/README.md
index 8818673..8bf5680 100644
--- a/README.md
+++ b/README.md
@@ -1,71 +1,118 @@
-# utilities
+
trailmix/utilities
-Repository of utilities for deno written in typescript for trailmix🌤🦕🍣😼
-[![art djkittyplayz][art]](http://djkittyplayz.art/)
-[![codecov][codecov]](https://app.codecov.io/gh/trailmix/utilities)
-[![downloads][downloads]](https://deno.land/x/trailmix)
-[![goofus_colors goofus colors trailmix deno typescript][goofus]](https://deno.land/x/trailmix)
-
-[![svg][svg]](https://app.codecov.io/gh/trailmix/utilities)
+Repository of utilities for deno written in typescript for trailmix🌤🦕🍣😼
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
## Usage
-### Simple
+### Colors
+
+
+
+
+**Simple**
```typescript
// import fns and style helpers
import {
+ messageByFn,
messageByFnSpread,
messageByString,
messageByStringSpread,
- messageByFn,
+ random,
randomOpts,
randomStyleFn,
randomStyleString,
- random,
styles as s,
-} from 'https://deno.land/x/trailmix@1.0.3/mod.ts';
+} from "https://deno.land/x/trailmix@1.0.4/mod.ts";
// random StyleFn Message Functions
-console.log(messageByFn('hello', [s.cyan, s.bgRed])); // cyan text, red BG
-console.log(messageByFnSpread('test', s.yellow, s.bgRed)); // yellow text, red BG
+console.log(messageByFn("hello", [s.cyan, s.bgRed])); // cyan text, red BG
+console.log(messageByFnSpread("test", s.yellow, s.bgRed)); // yellow text, red BG
// random Style Functions
-console.log(randomStyleFn('emphasis')); // get a random emphasis typeof StyleFn {(str:string) => string}
-console.log(randomStyleString('color')); // get a random color string typeof Style
+console.log(randomStyleFn("emphasis")); // get a random emphasis typeof StyleFn {(str:string) => string}
+console.log(randomStyleString("color")); // get a random color string typeof Style
// random StyleString Message Functions
-console.log(messageByString('hello', [randomStyleString('color')])); // random text color
-console.log(messageByStringSpread('hello', randomStyleString('bgColor'))); // random background color
-console.log(messageByFnSpread('hello', s[randomStyleString('emphasis')])); // call style list with random style fn
-console.log(random('hello')); // get random style on this string (50% chance of color/bg/emphasis)
-console.log(random('hello', { color: true })); // get random color on this string
-console.log(random('hello', randomOpts({ color: true }))); // get random color 100%, (50% chance for others)
+console.log(messageByString("hello", [randomStyleString("color")])); // random text color
+console.log(messageByStringSpread("hello", randomStyleString("bgColor"))); // random background color
+console.log(messageByFnSpread("hello", s[randomStyleString("emphasis")])); // call style list with random style fn
+console.log(random("hello")); // get random style on this string (50% chance of color/bg/emphasis)
+console.log(random("hello", { color: true })); // get random color on this string
+console.log(random("hello", randomOpts({ color: true }))); // get random color 100%, (50% chance for others)
```
-### Complex
+**Complex**
```typescript
// import the class and style helpers
-import { Color as C, styles as s } from 'https://deno.land/x/trailmix@1.0.1/mod.ts';
-import type { Styles } from 'https://deno.land/x/trailmix@1.0.1/mod.ts';
+import {
+ Color as C,
+ styles as s,
+} from "https://deno.land/x/trailmix@1.0.4/mod.ts";
+import type { Styles } from "https://deno.land/x/trailmix@1.0.4/mod.ts";
// you can use defined or anon functions
function test(str: string) {
- return str + 'defined function';
+ return str + "defined function";
}
const byFnConfAlpha = [
C.randomStyleFn(), // randoms return a random text color by default
test,
- C.randomStyleFn('bgColor'),
+ C.randomStyleFn("bgColor"),
(str: string) => {
// anon functions can be used
- return str + C.random('anon function', { emphasis: true });
+ return str + C.random("anon function", { emphasis: true });
},
];
const rConf = { color: true, bgColor: true, emphasis: false };
const byFnConfBeta = [
C.stylesMap.color.brightBlue, // stylesMap is ordered by color|bgColor|emphasis
(str: string) => {
- return str + 'anon function';
+ return str + "anon function";
},
C.stylesMap.color.yellow,
C.stylesMap.bgColor.bgBrightCyan,
@@ -75,23 +122,79 @@ const byFnConfBeta = [
C.stylesMap.bgColor.bgBrightYellow,
test,
(str: string) => {
- return 'anon function' + str;
+ return "anon function" + str;
},
C.styles.bgBrightYellow,
];
-const _sList: Styles[] = ['cyan', 'bgMagenta', 'underline']; // list of Style strings
-console.log(C.messageByFnSpread('test', ...byFnConfAlpha)); // spread StyleFns
-console.log(C.messageByFnSpread('test', ...byFnConfBeta));
-console.log(C.messageByString('this is not a spring spread', ['cyan', 'bgMagenta', 'underline'])); // no spread
-console.log(C.messageByStringSpread('a spring spread', 'green', 'bgBlack', 'strikethrough')); // spreading Style strings
-console.log(C.messageByStringSpread('a spring spread again with a var', ..._sList));
-console.log(C.random('test some string', rConf)); // random function
+const _sList: Styles[] = ["cyan", "bgMagenta", "underline"]; // list of Style strings
+console.log(C.messageByFnSpread("test", ...byFnConfAlpha)); // spread StyleFns
+console.log(C.messageByFnSpread("test", ...byFnConfBeta));
+console.log(
+ C.messageByString("this is not a spring spread", [
+ "cyan",
+ "bgMagenta",
+ "underline",
+ ]),
+); // no spread
+console.log(
+ C.messageByStringSpread(
+ "a spring spread",
+ "green",
+ "bgBlack",
+ "strikethrough",
+ ),
+); // spreading Style strings
+console.log(
+ C.messageByStringSpread("a spring spread again with a var", ..._sList),
+);
+console.log(C.random("test some string", rConf)); // random function
```
-## [CONTRIBUTE](CONTRIBUTE.md)
+### Config
+
+
+
+
+**Simple**
+
+```typescript
+import { EnvConfig, StringConfig } from "https://deno.land/x/trailmix@1.0.4/mod.ts";
+
+Deno.env.set("DEFAULT_TEST1", "val1"); // set example env var in DEFAULT namespace
+// slurp up env vars
+console.log(EnvConfig.parseEnv()); // should have { test1: "val1" }
+// something more complex
+Deno.env.set("DEFAULT_CONSOLE_LEVEL", "DEBUG"); // set log level in DEFAULT namespace
+console.log(EnvConfig.parseEnv()); // should have { test1: "val1", console: { level: "DEBUG" } }
+// this is good for cmd line arguments (--consoleLevel DEBUG)
+console.log(StringConfig.parseEnv({ test1: "val1", consoleLevel: "DEBUG" })); // should have same as above
+```
+
+**Complex**
+
+```typescript
+import { Config, EnvConfig, StringConfig } from "https://deno.land/x/trailmix@1.0.4/mod.ts";
-[goofus]: https://trailmix-images.s3.amazonaws.com/gooface/gooface-color.png
-[art]: https://img.shields.io/badge/art-djkittyplayz-yellow
-[codecov]: https://codecov.io/gh/trailmix/utilities/branch/master/graph/badge.svg?token=96CJ5IPAAN
-[downloads]: https://img.shields.io/github/downloads/trailmix/utilities/total
-[svg]: https://codecov.io/gh/trailmix/utilities/branch/master/graphs/tree.svg
+// lets use our own namespace with a config file
+const c = await new Config({
+ namespace: "TRAILMIX",
+ prefix: "trailmixString.config",
+}).init();
+// inside trailmixString.config.ts/tsx
+export default {
+ consoleFormat: "json",
+};
+console.log(new StringConfig(c).parseLog()); // will give a log config with {console: { format: "json" } }
+// now lets take into account env vars
+Deno.env.set("TRAILMIX_CONSOLE_FORMAT", "console");
+console.log(new EnvConfig(c).parseLog()); // will give a log config with {console: { format: "console" } }
+```
+
+### Log
+
+### Watch
+
+## [CONTRIBUTE](CONTRIBUTE.md)
diff --git a/color/Color.d.ts b/color/Color.d.ts
deleted file mode 100644
index 380038d..0000000
--- a/color/Color.d.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import type { styleEnum, EnumColor, EnumBgColor, EnumEmphasis } from 'trailmix/color/enum.ts';
-
-export type StyleTypes = Exclude;
-// list of all style strings
-export type Styles = keyof typeof EnumColor | keyof typeof EnumBgColor | keyof typeof EnumEmphasis;
-
-// generic style function string return string
-export type StyleFn = (str: string) => string;
-
-// for each style type use the styleEnum to get each name
-export type StylesMap = {
- [key in StyleTypes]: {
- [e in keyof typeof styleEnum[key] as Styles]: StyleFn;
- };
-};
-
-// map of all styles to a function
-export type StyleMap = Record;
-
-// options by string
-export type StyleOptions = {
- [key in StyleTypes]?: keyof typeof styleEnum[key];
-};
-// random options bools
-export type RandomStyleOptions = {
- [key in StyleTypes]?: boolean;
-};
diff --git a/color/Color.ts b/color/Color.ts
deleted file mode 100644
index ce9c1c5..0000000
--- a/color/Color.ts
+++ /dev/null
@@ -1,124 +0,0 @@
-import * as colors from 'fmt/colors.ts';
-import type { StylesMap, StyleMap, StyleFn, Styles, StyleTypes, RandomStyleOptions } from 'trailmix/color/Color.d.ts';
-import { EnumColor, EnumBgColor, EnumEmphasis } from 'trailmix/color/enum.ts';
-
-export default class Color {
- public static stylesMap: StylesMap = {
- color: Color._get_style_map(EnumColor),
- bgColor: Color._get_style_map(EnumBgColor),
- emphasis: Color._get_style_map(EnumEmphasis),
- };
- public static styles: StyleMap = {
- ...Color.stylesMap.color,
- ...Color.stylesMap.bgColor,
- ...Color.stylesMap.emphasis,
- };
- // list of style strings
- private static _styleList: Record = {
- color: Object.keys(Color.stylesMap.color) as Styles[],
- bgColor: Object.keys(Color.stylesMap.bgColor) as Styles[],
- emphasis: Object.keys(Color.stylesMap.emphasis) as Styles[],
- };
-
- /**
- * pass in string and formatting fns to format string with color and style
- // * @public
- // * @static
- // * @param str string to format
- // * @param fns functions to use
- // * @returns formatted string
- // * @example
- // * console.log(Color.messageByFn('hello', [Color.color.cyan, Color.bgColor.bgRed]))
- // */
- public static messageByFn(str: string, styles?: (StyleFn | undefined)[]): string {
- let msg = str;
- if (styles !== undefined)
- styles.forEach((style) => {
- if (style !== undefined) msg = style(msg);
- });
- return msg;
- }
- public static messageByFnSpread(str: string, ...styles: (StyleFn | undefined)[]): string {
- let msg = str;
- if (styles !== undefined)
- styles.forEach((style) => {
- if (style !== undefined) msg = style(msg);
- });
- return msg;
- }
- public static messageByString(str: string, styles: (Styles | undefined)[]): string {
- let msg = str;
- if (styles !== undefined)
- styles.forEach((style) => {
- if (style !== undefined) msg = Color.styles[style](msg);
- });
- return msg;
- }
- public static messageByStringSpread(str: string, ...styles: (Styles | undefined)[]): string {
- let msg = str;
- if (styles !== undefined)
- styles.forEach((style) => {
- if (style !== undefined) msg = Color.styles[style](msg);
- });
- return msg;
- }
-
- public static random(str: string, { color, bgColor, emphasis }: RandomStyleOptions = Color.randomOpts()): string {
- const c = [undefined, false].includes(color) ? undefined : Color.randomStyleFn();
- const bgC = [undefined, false].includes(bgColor) ? undefined : Color.randomStyleFn('bgColor');
- const e = [undefined, false].includes(emphasis) ? undefined : Color.randomStyleFn('emphasis');
- const r: Array = new Array(c ?? undefined, bgC ?? undefined, e ?? undefined);
- return Color.messageByFn(str, r);
- }
- public static randomOpts({ color, bgColor, emphasis }: RandomStyleOptions = {}): RandomStyleOptions {
- const ret: RandomStyleOptions = {
- color: color ?? Math.random() >= 0.5 ? true : false,
- bgColor: bgColor ?? Math.random() >= 0.5 ? true : false,
- emphasis: emphasis ?? Math.random() >= 0.5 ? true : false,
- };
- return ret;
- }
- /**
- *
- * @param type pass in a string type of style
- * @returns {StyleFn} random function of type EnumColor|EnumBgColor|EnumEmphasis
- */
- public static randomStyleFn(type: StyleTypes = 'color'): StyleFn {
- return Color.styles[Color.randomStyleString(type)];
- }
- public static randomStyleString(type: StyleTypes = 'color'): Styles {
- const styleNum = Color._randomNumber(Color._styleList[type].length);
- return Color._styleList[type][styleNum];
- }
- // get map of name, style function
- private static _get_style_map(s: Object): StyleMap {
- return Object.fromEntries(
- Object.entries(colors)
- .concat([['clear', (str: string) => str]])
- .flatMap(([style, fn]) => {
- return [
- ...(s !== undefined && Object.values(s).filter((_style) => _style === style).length > 0
- ? [[String(style), fn]]
- : []),
- ];
- }),
- );
- }
- /**
- * @param max max number to find random number (min is 0)
- * @returns random number within len
- */
- private static _randomNumber(max = 1): number {
- return Number(((max - 1) * Number(Math.random())).toFixed(0));
- }
-}
-export const messageByFn = Color.messageByFn;
-export const messageByFnSpread = Color.messageByFnSpread;
-export const messageByString = Color.messageByString;
-export const messageByStringSpread = Color.messageByStringSpread;
-export const random = Color.random;
-export const randomOpts = Color.randomOpts;
-export const randomStyleFn = Color.randomStyleFn;
-export const randomStyleString = Color.randomStyleString;
-export const stylesMap: StylesMap = Color.stylesMap;
-export const styles: StyleMap = Color.styles;
diff --git a/color/Color_test.ts b/color/Color_test.ts
deleted file mode 100644
index 007297b..0000000
--- a/color/Color_test.ts
+++ /dev/null
@@ -1,329 +0,0 @@
-import {
- default as Color,
- messageByFn,
- messageByFnSpread,
- messageByString,
- messageByStringSpread,
- random,
- randomOpts,
- randomStyleFn,
- randomStyleString,
- stylesMap,
-} from 'trailmix/color/Color.ts';
-import { styleEnum } from 'trailmix/color/enum.ts';
-import type { Styles, StyleFn } from 'trailmix/color/Color.d.ts';
-import { assertStrictEquals, assertNotEquals } from 'testing/asserts.ts';
-import { Table, Row, Cell } from 'cliffy/table';
-
-let testCases: string[] = [];
-let testName: string;
-const ogConsole = console.log;
-let table = resetTable();
-function resetTable(table?: []): Table {
- return (
- new Table()
- .body(table ?? [])
- // .maxColWidth(100)
- .border(true)
- .padding(1)
- .indent(2)
- );
-}
-function consoleMock(...data: string[]) {
- const expected = Array.isArray(testCases) ? testCases.filter((test) => test === data.join(''))[0] : testCases;
- const actual = data.join('');
- try {
- assertNotEquals(expected, '', `Did not find matching string in [testCases]\n ${JSON.stringify(testCases)}`);
- assertStrictEquals(
- actual,
- expected,
- `console.log() messages failure: (actual !== expected)\n "${actual}" !== "${expected}"`,
- );
- if (typeof JSON.parse(actual) !== 'object')
- assertStrictEquals(
- JSON.parse(actual),
- JSON.parse(expected),
- `console.log() JSON.parse() messages failure: (actual !== expected)\n "${actual}" !== "${expected}"`,
- );
- table.push(
- Row.from([
- Cell.from('🧪🧪🧪🧪\t\x1b[1m\x1b[92m\x1b[4m' + testName.trim() + '\x1b[24m\x1b[39m\x1b[22m\n').colSpan(3),
- ]).border(false),
- [actual, '===', expected],
- );
- if (typeof JSON.parse(actual) !== 'object') table.push([JSON.parse(actual), '===', JSON.parse(expected)]);
- } catch (e) {
- table.push(
- Row.from([
- Cell.from('🚨🚨🚨🚨\t\x1b[1m\x1b[91m\x1b[4m' + testName.trim() + '\x1b[24m\x1b[39m\x1b[22m' + e + '\n').colSpan(
- 3,
- ),
- ]).border(false),
- [actual, '!==', expected],
- [JSON.parse(actual ?? []), '!==', JSON.parse(expected ?? [])],
- );
- }
-}
-
-const tests = {
- string: {
- random: {
- color: {
- color: false,
- },
- bgColor: {
- bgColor: false,
- },
- emphasis: {
- emphasis: false,
- },
- },
- randomOpts: { ...Object.keys(styleEnum).filter((key) => key !== 'suffix') },
- randomStyleFn: { ...Object.keys(styleEnum).filter((key) => key !== 'suffix') },
- randomStyleString: { ...Object.keys(styleEnum).filter((key) => key !== 'suffix') },
- },
- stringEmpty: {
- random: {
- color: {},
- },
- messageByFn: {
- fixed: [],
- },
- messageByString: {
- fixed: [],
- },
- },
- undefined: {
- random: undefined,
- },
- stringUndefined: {
- random: {
- color: {
- color: undefined,
- },
- bgColor: {
- bgColor: undefined,
- },
- emphasis: {
- emphasis: undefined,
- },
- },
- messageByFn: {
- fixed: [undefined],
- fixedU: [stylesMap.color.red, undefined],
- },
- messageByString: {
- fixedU: ['red', undefined],
- fixed: [undefined],
- },
- },
- stringColor: {
- random: {
- color: {
- color: true,
- },
- },
- messageByFn: {
- fixed: [stylesMap.color.green],
- fixedU: [stylesMap.color.red, undefined],
- random: [randomStyleFn('color')],
- randomU: [randomStyleFn('color'), undefined],
- },
- messageByString: {
- fixed: ['green'],
- fixedU: ['red', undefined],
- random: [randomStyleString('color')],
- randomU: [randomStyleString('color'), undefined],
- },
- },
- stringBgColor: {
- random: {
- color: {
- bgColor: true,
- },
- },
- messageByFn: {
- fixed: [stylesMap.bgColor.bgBrightRed],
- random: [randomStyleFn('bgColor')],
- },
- messageByString: {
- fixed: ['bgBrightRed'],
- random: [randomStyleString('bgColor')],
- },
- },
- stringEmphasis: {
- random: {
- color: {
- emphasis: true,
- },
- },
- messageByFn: {
- fixed: [stylesMap.emphasis.bold],
- random: [randomStyleFn('emphasis')],
- },
- messageByString: {
- fixed: ['bold'],
- random: [randomStyleString('emphasis')],
- },
- },
- stringColorBgColor: {
- random: {
- color: {
- color: true,
- bgColor: true,
- },
- },
- messageByFn: {
- fixed: [stylesMap.color.green, stylesMap.bgColor.bgBrightRed],
- random: [randomStyleFn('color'), randomStyleFn('bgColor')],
- },
- messageByString: {
- fixed: ['green', 'bgBrightRed'],
- random: [randomStyleString('color'), randomStyleString('bgColor')],
- },
- },
- stringColorBgColorEmphasis: {
- random: {
- color: {
- color: true,
- bgColor: true,
- emphasis: true,
- },
- },
- messageByFn: {
- fixed: [stylesMap.color.green, stylesMap.bgColor.bgBrightRed, stylesMap.emphasis.bold],
- random: [randomStyleFn('color'), randomStyleFn('bgColor'), randomStyleFn('emphasis')],
- },
- messageByString: {
- fixed: ['green', 'bgBrightRed', 'bold'],
- random: [randomStyleString('color'), randomStyleString('bgColor'), randomStyleString('emphasis')],
- },
- },
- stringBgColorEmphasis: {
- random: {
- color: {
- bgColor: true,
- emphasis: true,
- },
- },
- messageByFn: {
- fixed: [stylesMap.bgColor.bgBrightRed, stylesMap.emphasis.bold],
- random: [randomStyleFn('bgColor'), randomStyleFn('emphasis')],
- },
- messageByString: {
- fixed: ['bgBrightRed', 'bold'],
- random: [randomStyleString('bgColor'), randomStyleString('emphasis')],
- },
- },
- stringColorEmphasis: {
- random: {
- color: {
- color: true,
- emphasis: true,
- },
- },
- messageByFn: {
- fixed: [stylesMap.color.green, stylesMap.emphasis.bold],
- random: [randomStyleFn('color'), randomStyleFn('emphasis')],
- },
- messageByString: {
- fixed: ['green', 'bold'],
- random: [randomStyleString('color'), randomStyleString('emphasis')],
- },
- },
-};
-
-for (const style of Object.keys(stylesMap)) {
- // @ts-ignore
- for (const fn of Object.keys(stylesMap[style])) {
- Deno.test({
- name: `Color.ts`,
- fn: () => {
- testName = `style:${style}, test:${fn}`;
- // @ts-ignore
- const args = stylesMap[style][fn];
- let msg = '';
- msg = JSON.stringify(args(style));
- console.log = consoleMock;
- testCases = [msg];
- console.log(msg);
- console.log = ogConsole;
- if (
- Object.keys(stylesMap).length - 1 === Object.keys(stylesMap).indexOf(style) &&
- // @ts-ignore
- Object.keys(stylesMap[style]).length - 1 === Object.keys(stylesMap[style]).indexOf(fn)
- ) {
- table.render();
- table = resetTable();
- }
- },
- });
- }
-}
-for (const test of Object.keys(tests)) {
- // @ts-ignore
- for (const fn of Object.keys(tests[test])) {
- for (const obj of [true, false]) {
- // @ts-ignore
- for (const stylefn of Object.keys(tests[test][fn] ?? { undefined: undefined })) {
- for (const spread of [true, false]) {
- Deno.test({
- name: `Color.ts`,
- fn: () => {
- testName = `${test}, fn:${fn}, styleFn:${stylefn}, spread:${spread}, fromObj:${obj}\n`;
- ogConsole(testName);
- // @ts-ignore
- const args = stylefn === 'undefined' ? tests[test][fn] : tests[test][fn][stylefn];
- let TmessageByStringSpread = messageByStringSpread;
- let TmessageByString = messageByString;
- let TmessageByFnSpread = messageByFnSpread;
- let TmessageByFn = messageByFn;
- let TrandomOpts = randomOpts;
- let TrandomStyleFn = randomStyleFn;
- let TrandomStyleString = randomStyleString;
- let Trandom = random;
- if (obj) {
- TmessageByStringSpread = Color.messageByStringSpread;
- TmessageByString = Color.messageByString;
- TmessageByFnSpread = Color.messageByFnSpread;
- TmessageByFn = Color.messageByFn;
- TrandomOpts = Color.randomOpts;
- TrandomStyleFn = Color.randomStyleFn;
- TrandomStyleString = Color.randomStyleString;
- Trandom = Color.random;
- }
- let msg = '';
- if (fn === 'messageByString') {
- if (spread) msg = JSON.stringify(TmessageByStringSpread(test, ...(args as Styles[])));
- else msg = JSON.stringify(TmessageByString(test, args as Styles[]));
- }
- if (fn === 'messageByFn') {
- if (spread) msg = JSON.stringify(TmessageByFnSpread(test, ...(args as StyleFn[])));
- else msg = JSON.stringify(TmessageByFn(test, args as StyleFn[]));
- }
- if (fn === 'randomOpts') msg = JSON.stringify(TrandomOpts(args));
- if (fn === 'randomStyleFn') msg = JSON.stringify(TrandomStyleFn(args)(test));
- if (fn === 'randomStyleString') msg = JSON.stringify(TrandomStyleString(args));
- if (fn === 'random') msg = JSON.stringify(Trandom(test, args));
- console.log = consoleMock;
- testCases = [msg];
- console.log(msg);
- console.log = ogConsole;
- if (
- Object.keys(tests).length - 1 === Object.keys(tests).indexOf(test) &&
- // @ts-ignore
- Object.keys(tests[test]).length - 1 === Object.keys(tests[test]).indexOf(fn) &&
- // @ts-ignore
- Object.keys(tests[test][fn]).length - 1 === Object.keys(tests[test][fn]).indexOf(stylefn) &&
- !spread
- ) {
- table.render();
- table = resetTable();
- }
- },
- });
- }
- }
- }
- }
-}
diff --git a/import_map.json b/import_map.json
index 4f6f0b0..00a5c69 100644
--- a/import_map.json
+++ b/import_map.json
@@ -1,9 +1,13 @@
{
"imports": {
- "trailmix/": "./",
- "trailmix/color": "./color/mod.ts",
+ "trailmix/": "./src/",
+ "test/": "./test/",
+ "uuid/": "https://deno.land/std@0.91.0/uuid/",
+ "fs/": "https://deno.land/std@0.91.0/fs/",
+ "path/": "https://deno.land/std@0.91.0/path/",
"testing/": "https://deno.land/std@0.91.0/testing/",
"fmt/": "https://deno.land/std@0.91.0/fmt/",
+ "log/": "https://deno.land/std@0.84.0/log/",
"cliffy/table": "https://deno.land/x/cliffy@v0.18.1/table/mod.ts"
}
}
diff --git a/mod.ts b/mod.ts
index 766c58f..f2a10fe 100644
--- a/mod.ts
+++ b/mod.ts
@@ -1,15 +1,3 @@
-export type { Styles } from 'trailmix/color/mod.ts';
-export {
- Color,
- messageByFn,
- messageByFnSpread,
- messageByString,
- messageByStringSpread,
- random,
- randomOpts,
- randomStyleFn,
- randomStyleString,
- styleEnum,
- styles,
- stylesMap,
-} from 'trailmix/color/mod.ts';
+export * as config from "trailmix/config/mod.ts";
+export * as color from "trailmix/color/mod.ts";
+export * as common from "trailmix/common/mod.ts";
diff --git a/package.json b/package.json
deleted file mode 100644
index 841e6b7..0000000
--- a/package.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "name": "utilities",
- "version": "1.0.1",
- "description": "A lib of utilities for trailmix.",
- "main": "mod.ts",
- "scripts": {
- "test": "deno test --unstable --allow-net --import-map=import_map.json **/*_test.ts",
- "test-one": "deno test --unstable --allow-net --import-map=import_map.json",
- "test-inspect": "deno test --unstable --allow-net --import-map=import_map.json --inspect **/*_test.ts",
- "test-coverage": "deno test --unstable --allow-net --import-map=import_map.json --coverage=./coverage/output **/*_test.ts",
- "coverage": "deno coverage --unstable ./coverage --lcov > ./coverage/lcov.info",
- "coverage-html": "genhtml -o coverage/html ./coverage/lcov.info"
- },
- "author": "trilom ",
- "license": "MIT",
- "devDependencies": {
- "@typescript-eslint/eslint-plugin": "^4.11.0",
- "@typescript-eslint/parser": "^4.11.0",
- "codecov": "^3.8.1",
- "eslint": "^7.16.0",
- "eslint-config-alloy": "^3.9.0",
- "eslint-plugin-react": "^7.21.5",
- "npm-run-all": "^4.1.5",
- "prettier": "^2.2.1",
- "typescript": "^4.1.3"
- }
-}
diff --git a/src/color/Color.d.ts b/src/color/Color.d.ts
new file mode 100644
index 0000000..a3a340d
--- /dev/null
+++ b/src/color/Color.d.ts
@@ -0,0 +1,35 @@
+import type {
+ EnumBgColor,
+ EnumColor,
+ EnumEmphasis,
+ styleEnum,
+} from "trailmix/color/enum.ts";
+
+export type StyleType = Exclude;
+// list of all style strings
+export type Style =
+ | keyof typeof EnumColor
+ | keyof typeof EnumBgColor
+ | keyof typeof EnumEmphasis;
+
+// generic style function string return string
+export type StyleFn = (str: string) => string;
+
+// for each style type use the styleEnum to get each name
+export type StyleTypeMap = {
+ [key in StyleType]: {
+ [e in keyof typeof styleEnum[key] as Style]: StyleFn;
+ };
+};
+
+// map of all styles to a function
+export type StyleMap = Record