paraphrase 3.1.0-rc-dcd4648 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -4
- package/index.js +4 -3
- package/index.mjs +4 -3
- package/package.json +1 -4
- package/types/index.d.ts +20 -12
- package/types/isObject/index.d.ts +2 -2
- package/types/notate/index.d.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
# 3.1.0 2022-11-29
|
|
2
|
+
|
|
3
|
+
## Features
|
|
4
|
+
|
|
5
|
+
Add type definitions for TypeScript.
|
|
6
|
+
|
|
7
|
+
## Internal
|
|
8
|
+
|
|
9
|
+
Move to TypeScript.
|
|
10
|
+
|
|
1
11
|
# 3.0.0 2021-09-21
|
|
2
12
|
|
|
3
13
|
## Breaking change
|
|
4
14
|
|
|
5
|
-
|
|
15
|
+
- All exports are named.
|
|
6
16
|
|
|
7
17
|
```js
|
|
8
18
|
import { paraphrase } from "paraphrase";
|
|
@@ -20,6 +30,4 @@ import { dollar } from "paraphrase";
|
|
|
20
30
|
|
|
21
31
|
## Breaking change
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
If you are using a bundler with babel, make sure you transpile this package to your liking
|
|
33
|
+
- Remove compiled version: If you are using a bundler with babel, make sure you transpile this package to your liking.
|
package/index.js
CHANGED
|
@@ -59,15 +59,16 @@ var VALID_RESULT_TYPES = Object.seal([
|
|
|
59
59
|
"string",
|
|
60
60
|
"number"
|
|
61
61
|
]);
|
|
62
|
-
function paraphrase(...
|
|
62
|
+
function paraphrase(...args) {
|
|
63
63
|
const options = {
|
|
64
64
|
recursive: true,
|
|
65
65
|
resolve: true,
|
|
66
66
|
clean: false
|
|
67
67
|
};
|
|
68
|
-
if (
|
|
69
|
-
Object.assign(options,
|
|
68
|
+
if (args.length && isObject(args[args.length - 1])) {
|
|
69
|
+
Object.assign(options, args.pop());
|
|
70
70
|
}
|
|
71
|
+
const patterns = args.flat().filter((arg) => arg instanceof RegExp);
|
|
71
72
|
Object.freeze(patterns);
|
|
72
73
|
function phraser(string = "", data, ...replacements) {
|
|
73
74
|
if (typeof string !== "string") {
|
package/index.mjs
CHANGED
|
@@ -28,15 +28,16 @@ var VALID_RESULT_TYPES = Object.seal([
|
|
|
28
28
|
"string",
|
|
29
29
|
"number"
|
|
30
30
|
]);
|
|
31
|
-
function paraphrase(...
|
|
31
|
+
function paraphrase(...args) {
|
|
32
32
|
const options = {
|
|
33
33
|
recursive: true,
|
|
34
34
|
resolve: true,
|
|
35
35
|
clean: false
|
|
36
36
|
};
|
|
37
|
-
if (
|
|
38
|
-
Object.assign(options,
|
|
37
|
+
if (args.length && isObject(args[args.length - 1])) {
|
|
38
|
+
Object.assign(options, args.pop());
|
|
39
39
|
}
|
|
40
|
+
const patterns = args.flat().filter((arg) => arg instanceof RegExp);
|
|
40
41
|
Object.freeze(patterns);
|
|
41
42
|
function phraser(string = "", data, ...replacements) {
|
|
42
43
|
if (typeof string !== "string") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paraphrase",
|
|
3
|
-
"version": "3.1.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "🧩 Create flavoured string template interpolation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"string",
|
|
@@ -52,8 +52,5 @@
|
|
|
52
52
|
"jest": "^29.3.1",
|
|
53
53
|
"prettier": "^2.8.0",
|
|
54
54
|
"ts-jest": "^29.0.3"
|
|
55
|
-
},
|
|
56
|
-
"publishConfig": {
|
|
57
|
-
"tag": "typescript"
|
|
58
55
|
}
|
|
59
56
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -12,25 +12,33 @@ interface IParaphraseOptions {
|
|
|
12
12
|
*/
|
|
13
13
|
clean?: boolean;
|
|
14
14
|
}
|
|
15
|
-
interface
|
|
16
|
-
(
|
|
15
|
+
interface Phraser {
|
|
16
|
+
(
|
|
17
|
+
/**
|
|
18
|
+
* Template string to parse
|
|
19
|
+
*/
|
|
20
|
+
string: string | undefined,
|
|
21
|
+
/**
|
|
22
|
+
* Data to use for interpolation, preferrably an object, but an array will work too, and a primitive values will be treated as an array of "...rest" arguments
|
|
23
|
+
*/
|
|
24
|
+
...data: (Record<string, any> | any)[]): string;
|
|
17
25
|
patterns: RegExp[];
|
|
18
26
|
}
|
|
19
27
|
/**
|
|
20
28
|
* Create new paraphrase method instance
|
|
21
|
-
* @param {...RegExp[]} replacers
|
|
22
|
-
* @param {IParaphraseOptions} [options]
|
|
23
|
-
* @returns {
|
|
29
|
+
* @param {...RegExp[]} replacers[] One or more patterns to use for string replacement
|
|
30
|
+
* @param {IParaphraseOptions} [options] The last argument can be an options object
|
|
31
|
+
* @returns {Phraser} phraser function instance
|
|
24
32
|
*
|
|
25
33
|
* @example const phraser = paraphrase(/\${([^{}]*)}/gm);
|
|
26
34
|
*
|
|
27
35
|
* phraser('Hello, ${name}', {name: 'Martin'})
|
|
28
36
|
*/
|
|
29
|
-
export declare function paraphrase(...
|
|
30
|
-
export declare const dollar:
|
|
31
|
-
export declare const double:
|
|
32
|
-
export declare const single:
|
|
33
|
-
export declare const percent:
|
|
34
|
-
export declare const hash:
|
|
35
|
-
export declare const loose:
|
|
37
|
+
export declare function paraphrase(...args: (RegExp | RegExp[] | IParaphraseOptions)[]): Phraser;
|
|
38
|
+
export declare const dollar: Phraser;
|
|
39
|
+
export declare const double: Phraser;
|
|
40
|
+
export declare const single: Phraser;
|
|
41
|
+
export declare const percent: Phraser;
|
|
42
|
+
export declare const hash: Phraser;
|
|
43
|
+
export declare const loose: Phraser;
|
|
36
44
|
export {};
|
package/types/notate/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Resolve dot notation strings
|
|
3
3
|
*
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {
|
|
6
|
-
* @return {
|
|
4
|
+
* @param {any} context Object to start notation search on (defaults to global scope)
|
|
5
|
+
* @param {string} [string=''] Dot notation representation
|
|
6
|
+
* @return {any} Whatever it finds / undefined
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* const obj = {
|