Skip to content

Commit

Permalink
Fixed circular dependencies for #17
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaakko Heusala committed Jul 14, 2024
1 parent e7c33e4 commit 4ef17a5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion entities/component/ComponentContent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023-2024. Sendanor <info@sendanor.fi>. All rights reserved.

import { prefixLines } from "../../functions/prefixLines";
import {
explainArrayOf,
isArrayOf,
Expand All @@ -9,7 +10,6 @@ import {
explainOk,
explainOr,
} from "../../types/explain";
import { prefixLines } from "../../types/String";
import { isUndefined } from "../../types/undefined";
import { Component } from "./Component";
import {
Expand Down
20 changes: 20 additions & 0 deletions functions/prefixLines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2024. Sendanor <info@sendanor.fi>. All rights reserved.

import { replaceAll } from "./replaceAll";

/**
* Returns the string with each line prefixed with another string.
*
* @param value The value
* @param prefix The prefix string
*/
export function prefixLines (
value : string,
prefix : string,
) : string {
return `${ prefix }${ replaceAll(
value,
"\n",
`\n${ prefix }`,
) }`;
}
8 changes: 4 additions & 4 deletions functions/replaceAll.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import { isString } from "../types/String";
import { default as _isString } from "lodash/isString";

/**
* Replaces all occurrences of a string in the input string.
Expand All @@ -13,9 +13,9 @@ import { isString } from "../types/String";
* @throws {TypeError} If `value`, `from`, or `to` are not strings.
*/
export function replaceAll (value: string, from: string, to: string): string {
if ( !isString(from) ) throw new TypeError('replaceAll: from is required');
if ( !isString(value) ) throw new TypeError('replaceAll: value is not a string');
if ( !isString(to) ) throw new TypeError('replaceAll: to is not a string');
if ( !_isString(from) ) throw new TypeError('replaceAll: from is required');
if ( !_isString(value) ) throw new TypeError('replaceAll: value is not a string');
if ( !_isString(to) ) throw new TypeError('replaceAll: to is not a string');
if ( from === '' ) return [ '', ...value.split(''), '' ].join(to);
let ret = '';
let p = 0;
Expand Down
31 changes: 9 additions & 22 deletions types/String.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Copyright (c) 2020-2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.
// Copyright (c) 2020-2024. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import { isNull } from "lodash";
import { default as _isString } from "lodash/isString";
import { default as _isSymbol } from "lodash/isSymbol";
import { replaceAll } from "../functions/replaceAll";
import { isUndefined } from "./undefined";
import { explainNot, explainOk, explainOr } from "./explain";
import { isNull } from "lodash";
import { isNumber } from "./Number";
import {
explainNot,
explainOk,
explainOr,
} from "./explain";
import { isFunction } from "./Function";
import { isNumber } from "./Number";
import { isUndefined } from "./undefined";

/**
*
Expand Down Expand Up @@ -261,19 +264,3 @@ export function parseNonEmptyString (value: any): string | undefined {
return `${value}`;
}

/**
* Returns the string with each line prefixed with another string.
*
* @param value The value
* @param prefix The prefix string
*/
export function prefixLines (
value: string,
prefix: string
) : string {
return `${prefix}${replaceAll(
value,
"\n",
`\n${prefix}`
)}`;
}
2 changes: 1 addition & 1 deletion types/explain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { default as _isString } from "lodash/isString";
import { default as _every } from "lodash/every";
import { default as _filter } from "lodash/filter";
import { map } from "../functions/map";
import { prefixLines } from "./String";
import { prefixLines } from "../functions/prefixLines";

/**
* Returned from explain functions when the value is OK.
Expand Down

0 comments on commit 4ef17a5

Please sign in to comment.