Skip to content

Commit

Permalink
move regex snippets into RegexSnippets namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaboud committed May 29, 2024
1 parent b4750be commit feb5a23
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions houston-common-lib/lib/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ResultAsync, okAsync, errAsync, safeTry, ok, err } from "neverthrow";
import { User } from "@/user";
import { Group } from "@/group";
import { FilesystemMount, parseFileSystemType } from "@/filesystem";
import { newlineSplitterRegex } from "@/syntax";
import { RegexSnippets } from "@/syntax";

export class ModeOctet {
r: boolean;
Expand Down Expand Up @@ -239,7 +239,7 @@ export class Path {
commandOptions
)
)
.map((proc) => proc.getStdout().trim().split(newlineSplitterRegex)[1])
.map((proc) => proc.getStdout().trim().split(RegexSnippets.newlineSplitter)[1])
.andThen((tokens) => {
const [source, mountpoint, realType] = tokens?.split(/\s+/g) ?? [];
if (
Expand Down
4 changes: 2 additions & 2 deletions houston-common-lib/lib/syntax/ini-syntax.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SyntaxParser } from "./syntax-parser";
import { Result, ok, err } from "neverthrow";
import { newlineSplitterRegex } from "./regex-snippets";
import { RegexSnippets } from "./regex-snippets";
import { KeyValueData, KeyValueSyntax } from "@/syntax/key-value-syntax";
import { ParsingError } from "@/errors";

Expand Down Expand Up @@ -55,7 +55,7 @@ export function IniSyntax(
? ({} as IniConfigData<string | [string, ...string[]]>)
: ({} as IniConfigData<string>);
let currentSection: string | null = null;
for (const [index, line] of text.split(newlineSplitterRegex).entries()) {
for (const [index, line] of text.split(RegexSnippets.newlineSplitter).entries()) {
if (line.trim() === "" || commentRegex.test(line)) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions houston-common-lib/lib/syntax/key-value-syntax.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SyntaxParser } from "@/syntax/syntax-parser";
import { ParsingError } from "@/errors";
import { Result, ok, err } from "neverthrow";
import { newlineSplitterRegex } from "./regex-snippets";
import { RegexSnippets } from "./regex-snippets";

export type KeyValueData<
TValue extends string | [string, ...string[]] = string,
Expand Down Expand Up @@ -53,7 +53,7 @@ export function KeyValueSyntax(
Result.combine(
text
// split lines
.split(newlineSplitterRegex)
.split(RegexSnippets.newlineSplitter)
.map(
(
line,
Expand Down
5 changes: 4 additions & 1 deletion houston-common-lib/lib/syntax/regex-snippets.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const newlineSplitterRegex = /(?<!\\)[\r\n]+/;
export namespace RegexSnippets {
export const newlineSplitter = /(?<!\\)[\r\n]+/;

}
4 changes: 2 additions & 2 deletions houston-common-ui/lib/components/ParsedTextArea.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, watch, defineModel, defineProps, withDefaults } from "vue";
import { type SyntaxParser, type SyntaxParserType, newlineSplitterRegex } from "@45drives/houston-common-lib";
import { type SyntaxParser, type SyntaxParserType, RegexSnippets } from "@45drives/houston-common-lib";
import { reportError } from '@/components/NotificationView.vue';
const props = withDefaults(defineProps<{
Expand Down Expand Up @@ -35,7 +35,7 @@ watch(keyValueData, onKeyValueDataChanged, { immediate: true, deep: true });
<template>
<textarea
name="global-advanced-settings"
:rows="Math.min(Math.max(textAreaContent.split(newlineSplitterRegex).length, minRows), maxRows)"
:rows="Math.min(Math.max(textAreaContent.split(RegexSnippets.newlineSplitter).length, minRows), maxRows)"
:disabled="disabled"
v-model="textAreaContent"
class="w-full input-textlike"
Expand Down

0 comments on commit feb5a23

Please sign in to comment.