Skip to content

Commit

Permalink
feat: add createLoosePattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Kraus committed Apr 16, 2024
1 parent 5afb9bf commit 24decb3
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 5 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ The only important whitespaces are ones inside quote pairs in the loose partial
looseStringTest(' [ "a", " b ", .... ', '["a"," b ","c "]'); // true
```

## ParsePattern Function
## parsePattern Function

Gives you information about a pattern:

Expand All @@ -212,3 +212,14 @@ parsePattern('["a", "b c", "d" ...');
// isStartPattern: true
// }
```

## createLoosePattern Function

Creates a loose pattern from an input string that matches that input string:

```js
const input = `[1, 2, 3,
4, 5, 6]`;
createLoosePattern(input); //=> '[1, 2, 3, 4, 5, 6]'
createLoosePattern(input, 5); //=> '[1, 2 ...'
```
15 changes: 15 additions & 0 deletions build/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export declare const REST_MARK = "...";
export declare const DEFAULT_MAX_PATTERN_BODY_LENGTH = 20;
/**
* Tests if a given input string can match the simple pattern string.
* That pattern string is a very simple expression, much simpler than a RegExp (see examples).
Expand Down Expand Up @@ -41,4 +42,18 @@ export declare const parsePattern: (patternStr: string) => {
isExactPattern: boolean;
isStartPattern: boolean;
};
/**
* creates a loose pattern from an input string
* @param str input string
* @param maxPatternBodyLength a threshold for a start-pattern creation. Limits the pattern body length. Dofaults to DEFAULT_MAX_PATTERN_BODY_LENGTH
* @returns loose patern that can match the input string
*
* @example
*
* const input = `[1, 2, 3
* 4, 5, 6]`;
* createLoosePattern(input, 5) //=> '[1, 2 ...'
*
*/
export declare const createLoosePattern: (str: string, maxPatternBodyLength?: number) => string;
export default looseStringTest;
24 changes: 23 additions & 1 deletion build/src/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/src/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions build/test/index.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 24decb3

Please sign in to comment.