paraphrase 3.1.0-rc-dcd4648 → 3.1.1
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/index.js +20 -3
- package/index.js.map +7 -0
- package/index.mjs +20 -3
- package/index.mjs.map +7 -0
- package/package.json +13 -9
- package/types/index.d.ts +20 -12
- package/CHANGELOG.md +0 -25
- package/types/flavours/index.d.ts +0 -1
- package/types/isObject/index.d.ts +0 -6
- package/types/notate/index.d.ts +0 -23
package/index.js
CHANGED
|
@@ -47,10 +47,25 @@ var isObject = (obj) => `${obj}` === "[object Object]";
|
|
|
47
47
|
|
|
48
48
|
// src/flavours/index.ts
|
|
49
49
|
var flavours = {
|
|
50
|
+
/**
|
|
51
|
+
* Template: 'Hello, ${name}'
|
|
52
|
+
*/
|
|
50
53
|
dollar: /\${([^{}]*)}/gm,
|
|
54
|
+
/**
|
|
55
|
+
* Template: 'Hello, {{name}}'
|
|
56
|
+
*/
|
|
51
57
|
double: /{{([^{}]*)}}/gm,
|
|
58
|
+
/**
|
|
59
|
+
* Template: 'Hello, {name}'
|
|
60
|
+
*/
|
|
52
61
|
single: /{([^{}]*)}/gm,
|
|
62
|
+
/**
|
|
63
|
+
* Template: 'Hello, #{name}'
|
|
64
|
+
*/
|
|
53
65
|
hash: /#{([^{}]*)}/gm,
|
|
66
|
+
/**
|
|
67
|
+
* Template: 'Hello, %{name}'
|
|
68
|
+
*/
|
|
54
69
|
percent: /%{([^{}]*)}/gm
|
|
55
70
|
};
|
|
56
71
|
|
|
@@ -59,15 +74,16 @@ var VALID_RESULT_TYPES = Object.seal([
|
|
|
59
74
|
"string",
|
|
60
75
|
"number"
|
|
61
76
|
]);
|
|
62
|
-
function paraphrase(...
|
|
77
|
+
function paraphrase(...args) {
|
|
63
78
|
const options = {
|
|
64
79
|
recursive: true,
|
|
65
80
|
resolve: true,
|
|
66
81
|
clean: false
|
|
67
82
|
};
|
|
68
|
-
if (
|
|
69
|
-
Object.assign(options,
|
|
83
|
+
if (args.length && isObject(args[args.length - 1])) {
|
|
84
|
+
Object.assign(options, args.pop());
|
|
70
85
|
}
|
|
86
|
+
const patterns = args.flat().filter((arg) => arg instanceof RegExp);
|
|
71
87
|
Object.freeze(patterns);
|
|
72
88
|
function phraser(string = "", data, ...replacements) {
|
|
73
89
|
if (typeof string !== "string") {
|
|
@@ -118,3 +134,4 @@ var loose = paraphrase(
|
|
|
118
134
|
percent,
|
|
119
135
|
single
|
|
120
136
|
});
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/index.ts", "src/notate/index.ts", "src/isObject/index.ts", "src/flavours/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { notate } from \"./notate/index\";\nimport { isObject } from \"./isObject/index\";\nimport { flavours } from \"./flavours/index\";\n\n/**\n * Valid types of results for the interpolated string\n */\nconst VALID_RESULT_TYPES: [\"string\", \"number\"] = Object.seal([\n \"string\",\n \"number\",\n]);\n\ninterface IParaphraseOptions {\n /**\n * Should continue to resolve result string until replacements have been exhausted\n */\n recursive?: boolean;\n /**\n * Should resolve dot notation within template\n */\n resolve?: boolean;\n /**\n * Should remove unmatched template instances\n */\n clean?: boolean;\n}\n\ninterface Phraser {\n (\n /**\n * Template string to parse\n */\n string: string | undefined,\n /**\n * 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\n */\n ...data: (Record<string, any> | any)[]\n ): string;\n patterns: RegExp[];\n}\n\n/**\n * Create new paraphrase method instance\n * @param {...RegExp[]} replacers[] One or more patterns to use for string replacement\n * @param {IParaphraseOptions} [options] The last argument can be an options object\n * @returns {Phraser} phraser function instance\n *\n * @example const phraser = paraphrase(/\\${([^{}]*)}/gm);\n *\n * phraser('Hello, ${name}', {name: 'Martin'})\n */\nexport function paraphrase(\n ...args: (RegExp | RegExp[] | IParaphraseOptions)[]\n): Phraser {\n const options: IParaphraseOptions = {\n recursive: true,\n resolve: true,\n clean: false,\n };\n if (args.length && isObject(args[args.length - 1])) {\n Object.assign(options, args.pop() as IParaphraseOptions);\n }\n const patterns = args.flat().filter((arg) => arg instanceof RegExp);\n\n Object.freeze(patterns);\n\n /**\n * phraser description\n * @param {string} string Template\n * @param {Object|(string|number)} data Data for filling\n * @param {...(string|number)} replacements Replacement for filling\n * @return {string} Result\n */\n function phraser(\n string: string = \"\",\n data: string | number | Record<string, any>,\n ...replacements: (string | number)[]\n ): string {\n if (typeof string !== \"string\") {\n throw new TypeError(\n `paraphrase expects first argument to be a string, got a ${typeof string} (${string})`\n );\n }\n\n if (!data) {\n return string;\n }\n\n if (VALID_RESULT_TYPES.includes(typeof data as any)) {\n data = [data, ...replacements];\n }\n\n /**\n * Replace method build with internal reference to the passed in data structure\n * @param {string} haystack The full string match\n * @param {string} needle The content to identify as data member\n * @return {string} Found value\n */\n function replace(haystack: string, needle: string): string {\n const replacement = options.resolve\n ? notate(data, needle.trim())\n : data[needle.trim()];\n\n return VALID_RESULT_TYPES.includes(typeof replacement as any)\n ? replacement\n : options.clean\n ? \"\"\n : haystack;\n }\n\n const result = (patterns as RegExp[]).reduce(\n (string: string, pattern: RegExp): string =>\n string.replace(pattern, replace),\n string\n );\n\n return !options.recursive || string === result\n ? result\n : phraser(result, data, ...replacements);\n }\n\n Object.defineProperty(phraser, \"patterns\", {\n get: () => patterns,\n });\n\n return phraser as Phraser;\n}\n\nexport const dollar = paraphrase(flavours.dollar);\nexport const double = paraphrase(flavours.double);\nexport const single = paraphrase(flavours.single);\nexport const percent = paraphrase(flavours.percent);\nexport const hash = paraphrase(flavours.hash);\nexport const loose = paraphrase(\n flavours.dollar,\n flavours.double,\n flavours.percent,\n flavours.hash,\n flavours.single\n);\n", "/**\n * Resolve dot notation strings\n *\n * @param {any} context Object to start notation search on (defaults to global scope)\n * @param {string} [string=''] Dot notation representation\n * @return {any} Whatever it finds / undefined\n *\n * @example\n * const obj = {\n * top_level: {\n * nested: {\n * value: 'My Value'\n * }\n * }\n * };\n *\n * notate(obj, 'top_level.nested.value');\n * // 'My Value'\n *\n * notate(obj, 'top_level.missing.value');\n * // undefined\n */\nexport function notate(source: any, string: string = \"\"): any {\n if (typeof string !== \"string\") {\n throw new TypeError(\n `Expected notation query to be a string, instead got ${typeof string} (${string})`\n );\n }\n return string\n .split(\".\")\n .reduce(\n (previous, current) =>\n typeof previous === \"object\" && previous ? previous[current] : previous,\n source\n );\n}\n", "/**\n * Is this a basic object?\n * @param {any} obj Target to test\n * @return {boolean} true if object\n */\nexport const isObject = (obj: any): boolean => `${obj}` === \"[object Object]\";\n", "export const flavours: Record<string, RegExp> = {\n /**\n * Template: 'Hello, ${name}'\n */\n dollar: /\\${([^{}]*)}/gm,\n /**\n * Template: 'Hello, {{name}}'\n */\n double: /{{([^{}]*)}}/gm,\n /**\n * Template: 'Hello, {name}'\n */\n single: /{([^{}]*)}/gm,\n /**\n * Template: 'Hello, #{name}'\n */\n hash: /#{([^{}]*)}/gm,\n /**\n * Template: 'Hello, %{name}'\n */\n percent: /%{([^{}]*)}/gm,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsBO,SAAS,OAAO,QAAa,SAAiB,IAAS;AAC5D,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI;AAAA,MACR,uDAAuD,OAAO,WAAW;AAAA,IAC3E;AAAA,EACF;AACA,SAAO,OACJ,MAAM,GAAG,EACT;AAAA,IACC,CAAC,UAAU,YACT,OAAO,aAAa,YAAY,WAAW,SAAS,OAAO,IAAI;AAAA,IACjE;AAAA,EACF;AACJ;;;AC9BO,IAAM,WAAW,CAAC,QAAsB,GAAG,UAAU;;;ACLrD,IAAM,WAAmC;AAAA;AAAA;AAAA;AAAA,EAI9C,QAAQ;AAAA;AAAA;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AS,YAAY;AAAA,IACzC,KAAK,MAAM;AAAA,EACb,CAAC;AAED,SAAO;AACT;AAEO,IAAM,SAAS,WAAW,SAAS,MAAM;AACzC,IAAM,SAAS,WAAW,SAAS,MAAM;AACzC,IAAM,SAAS,WAAW,SAAS,MAAM;AACzC,IAAM,UAAU,WAAW,SAAS,OAAO;AAC3C,IAAM,OAAO,WAAW,SAAS,IAAI;AACrC,IAAM,QAAQ;AAAA,EACnB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;",
|
|
6
|
+
"names": ["string"]
|
|
7
|
+
}
|
package/index.mjs
CHANGED
|
@@ -16,10 +16,25 @@ var isObject = (obj) => `${obj}` === "[object Object]";
|
|
|
16
16
|
|
|
17
17
|
// src/flavours/index.ts
|
|
18
18
|
var flavours = {
|
|
19
|
+
/**
|
|
20
|
+
* Template: 'Hello, ${name}'
|
|
21
|
+
*/
|
|
19
22
|
dollar: /\${([^{}]*)}/gm,
|
|
23
|
+
/**
|
|
24
|
+
* Template: 'Hello, {{name}}'
|
|
25
|
+
*/
|
|
20
26
|
double: /{{([^{}]*)}}/gm,
|
|
27
|
+
/**
|
|
28
|
+
* Template: 'Hello, {name}'
|
|
29
|
+
*/
|
|
21
30
|
single: /{([^{}]*)}/gm,
|
|
31
|
+
/**
|
|
32
|
+
* Template: 'Hello, #{name}'
|
|
33
|
+
*/
|
|
22
34
|
hash: /#{([^{}]*)}/gm,
|
|
35
|
+
/**
|
|
36
|
+
* Template: 'Hello, %{name}'
|
|
37
|
+
*/
|
|
23
38
|
percent: /%{([^{}]*)}/gm
|
|
24
39
|
};
|
|
25
40
|
|
|
@@ -28,15 +43,16 @@ var VALID_RESULT_TYPES = Object.seal([
|
|
|
28
43
|
"string",
|
|
29
44
|
"number"
|
|
30
45
|
]);
|
|
31
|
-
function paraphrase(...
|
|
46
|
+
function paraphrase(...args) {
|
|
32
47
|
const options = {
|
|
33
48
|
recursive: true,
|
|
34
49
|
resolve: true,
|
|
35
50
|
clean: false
|
|
36
51
|
};
|
|
37
|
-
if (
|
|
38
|
-
Object.assign(options,
|
|
52
|
+
if (args.length && isObject(args[args.length - 1])) {
|
|
53
|
+
Object.assign(options, args.pop());
|
|
39
54
|
}
|
|
55
|
+
const patterns = args.flat().filter((arg) => arg instanceof RegExp);
|
|
40
56
|
Object.freeze(patterns);
|
|
41
57
|
function phraser(string = "", data, ...replacements) {
|
|
42
58
|
if (typeof string !== "string") {
|
|
@@ -86,3 +102,4 @@ export {
|
|
|
86
102
|
percent,
|
|
87
103
|
single
|
|
88
104
|
};
|
|
105
|
+
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/notate/index.ts", "src/isObject/index.ts", "src/flavours/index.ts", "src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Resolve dot notation strings\n *\n * @param {any} context Object to start notation search on (defaults to global scope)\n * @param {string} [string=''] Dot notation representation\n * @return {any} Whatever it finds / undefined\n *\n * @example\n * const obj = {\n * top_level: {\n * nested: {\n * value: 'My Value'\n * }\n * }\n * };\n *\n * notate(obj, 'top_level.nested.value');\n * // 'My Value'\n *\n * notate(obj, 'top_level.missing.value');\n * // undefined\n */\nexport function notate(source: any, string: string = \"\"): any {\n if (typeof string !== \"string\") {\n throw new TypeError(\n `Expected notation query to be a string, instead got ${typeof string} (${string})`\n );\n }\n return string\n .split(\".\")\n .reduce(\n (previous, current) =>\n typeof previous === \"object\" && previous ? previous[current] : previous,\n source\n );\n}\n", "/**\n * Is this a basic object?\n * @param {any} obj Target to test\n * @return {boolean} true if object\n */\nexport const isObject = (obj: any): boolean => `${obj}` === \"[object Object]\";\n", "export const flavours: Record<string, RegExp> = {\n /**\n * Template: 'Hello, ${name}'\n */\n dollar: /\\${([^{}]*)}/gm,\n /**\n * Template: 'Hello, {{name}}'\n */\n double: /{{([^{}]*)}}/gm,\n /**\n * Template: 'Hello, {name}'\n */\n single: /{([^{}]*)}/gm,\n /**\n * Template: 'Hello, #{name}'\n */\n hash: /#{([^{}]*)}/gm,\n /**\n * Template: 'Hello, %{name}'\n */\n percent: /%{([^{}]*)}/gm,\n};\n", "import { notate } from \"./notate/index\";\nimport { isObject } from \"./isObject/index\";\nimport { flavours } from \"./flavours/index\";\n\n/**\n * Valid types of results for the interpolated string\n */\nconst VALID_RESULT_TYPES: [\"string\", \"number\"] = Object.seal([\n \"string\",\n \"number\",\n]);\n\ninterface IParaphraseOptions {\n /**\n * Should continue to resolve result string until replacements have been exhausted\n */\n recursive?: boolean;\n /**\n * Should resolve dot notation within template\n */\n resolve?: boolean;\n /**\n * Should remove unmatched template instances\n */\n clean?: boolean;\n}\n\ninterface Phraser {\n (\n /**\n * Template string to parse\n */\n string: string | undefined,\n /**\n * 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\n */\n ...data: (Record<string, any> | any)[]\n ): string;\n patterns: RegExp[];\n}\n\n/**\n * Create new paraphrase method instance\n * @param {...RegExp[]} replacers[] One or more patterns to use for string replacement\n * @param {IParaphraseOptions} [options] The last argument can be an options object\n * @returns {Phraser} phraser function instance\n *\n * @example const phraser = paraphrase(/\\${([^{}]*)}/gm);\n *\n * phraser('Hello, ${name}', {name: 'Martin'})\n */\nexport function paraphrase(\n ...args: (RegExp | RegExp[] | IParaphraseOptions)[]\n): Phraser {\n const options: IParaphraseOptions = {\n recursive: true,\n resolve: true,\n clean: false,\n };\n if (args.length && isObject(args[args.length - 1])) {\n Object.assign(options, args.pop() as IParaphraseOptions);\n }\n const patterns = args.flat().filter((arg) => arg instanceof RegExp);\n\n Object.freeze(patterns);\n\n /**\n * phraser description\n * @param {string} string Template\n * @param {Object|(string|number)} data Data for filling\n * @param {...(string|number)} replacements Replacement for filling\n * @return {string} Result\n */\n function phraser(\n string: string = \"\",\n data: string | number | Record<string, any>,\n ...replacements: (string | number)[]\n ): string {\n if (typeof string !== \"string\") {\n throw new TypeError(\n `paraphrase expects first argument to be a string, got a ${typeof string} (${string})`\n );\n }\n\n if (!data) {\n return string;\n }\n\n if (VALID_RESULT_TYPES.includes(typeof data as any)) {\n data = [data, ...replacements];\n }\n\n /**\n * Replace method build with internal reference to the passed in data structure\n * @param {string} haystack The full string match\n * @param {string} needle The content to identify as data member\n * @return {string} Found value\n */\n function replace(haystack: string, needle: string): string {\n const replacement = options.resolve\n ? notate(data, needle.trim())\n : data[needle.trim()];\n\n return VALID_RESULT_TYPES.includes(typeof replacement as any)\n ? replacement\n : options.clean\n ? \"\"\n : haystack;\n }\n\n const result = (patterns as RegExp[]).reduce(\n (string: string, pattern: RegExp): string =>\n string.replace(pattern, replace),\n string\n );\n\n return !options.recursive || string === result\n ? result\n : phraser(result, data, ...replacements);\n }\n\n Object.defineProperty(phraser, \"patterns\", {\n get: () => patterns,\n });\n\n return phraser as Phraser;\n}\n\nexport const dollar = paraphrase(flavours.dollar);\nexport const double = paraphrase(flavours.double);\nexport const single = paraphrase(flavours.single);\nexport const percent = paraphrase(flavours.percent);\nexport const hash = paraphrase(flavours.hash);\nexport const loose = paraphrase(\n flavours.dollar,\n flavours.double,\n flavours.percent,\n flavours.hash,\n flavours.single\n);\n"],
|
|
5
|
+
"mappings": ";AAsBO,SAAS,OAAO,QAAa,SAAiB,IAAS;AAC5D,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI;AAAA,MACR,uDAAuD,OAAO,WAAW;AAAA,IAC3E;AAAA,EACF;AACA,SAAO,OACJ,MAAM,GAAG,EACT;AAAA,IACC,CAAC,UAAU,YACT,OAAO,aAAa,YAAY,WAAW,SAAS,OAAO,IAAI;AAAA,IACjE;AAAA,EACF;AACJ;;;AC9BO,IAAM,WAAW,CAAC,QAAsB,GAAG,UAAU;;;ACLrD,IAAM,WAAmC;AAAA;AAAA;AAAA;AAAA,EAI9C,QAAQ;AAAA;AAAA;AAAA;AAA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AAAA,IACzC,KAAK,MAAM;AAAA,EACb,CAAC;AAED,SAAO;AACT;AAEO,IAAM,SAAS,WAAW,SAAS,MAAM;AACzC,IAAM,SAAS,WAAW,SAAS,MAAM;AACzC,IAAM,SAAS,WAAW,SAAS,MAAM;AACzC,IAAM,UAAU,WAAW,SAAS,OAAO;AAC3C,IAAM,OAAO,WAAW,SAAS,IAAI;AACrC,IAAM,QAAQ;AAAA,EACnB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;",
|
|
6
|
+
"names": ["string"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paraphrase",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "🧩 Create flavoured string template interpolation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"string",
|
|
@@ -40,6 +40,13 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"types": "./types/index.d.ts",
|
|
43
|
+
"files": [
|
|
44
|
+
"index.js",
|
|
45
|
+
"index.js.map",
|
|
46
|
+
"index.mjs",
|
|
47
|
+
"index.mjs.map",
|
|
48
|
+
"types/index.d.ts"
|
|
49
|
+
],
|
|
43
50
|
"scripts": {
|
|
44
51
|
"test": "jest",
|
|
45
52
|
"format": "prettier --write .",
|
|
@@ -47,13 +54,10 @@
|
|
|
47
54
|
"prepublishOnly": "npm run build"
|
|
48
55
|
},
|
|
49
56
|
"devDependencies": {
|
|
50
|
-
"@types/jest": "^29.
|
|
51
|
-
"esbuild": "^0.
|
|
52
|
-
"jest": "^29.
|
|
53
|
-
"prettier": "^2.8.
|
|
54
|
-
"ts-jest": "^29.0.
|
|
55
|
-
},
|
|
56
|
-
"publishConfig": {
|
|
57
|
-
"tag": "typescript"
|
|
57
|
+
"@types/jest": "^29.4.0",
|
|
58
|
+
"esbuild": "^0.17.4",
|
|
59
|
+
"jest": "^29.4.0",
|
|
60
|
+
"prettier": "^2.8.3",
|
|
61
|
+
"ts-jest": "^29.0.5"
|
|
58
62
|
}
|
|
59
63
|
}
|
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/CHANGELOG.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# 3.0.0 2021-09-21
|
|
2
|
-
|
|
3
|
-
## Breaking change
|
|
4
|
-
|
|
5
|
-
### All exports are named
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
import { paraphrase } from "paraphrase";
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
### Flavoured imports included
|
|
12
|
-
|
|
13
|
-
Flavoured pre-made versions should be imported from main entry and not from directory.
|
|
14
|
-
|
|
15
|
-
```js
|
|
16
|
-
import { dollar } from "paraphrase";
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
# 2.0.0 2021-05-11
|
|
20
|
-
|
|
21
|
-
## Breaking change
|
|
22
|
-
|
|
23
|
-
### Remove compiled version.
|
|
24
|
-
|
|
25
|
-
If you are using a bundler with babel, make sure you transpile this package to your liking
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const flavours: Record<string, RegExp>;
|
package/types/notate/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve dot notation strings
|
|
3
|
-
*
|
|
4
|
-
* @param {Object} context Object to start notation search (defaults to global scope)
|
|
5
|
-
* @param {String} [string=''] Dot notation representation
|
|
6
|
-
* @return {Any} Whatever it finds / undefined
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* const obj = {
|
|
10
|
-
* top_level: {
|
|
11
|
-
* nested: {
|
|
12
|
-
* value: 'My Value'
|
|
13
|
-
* }
|
|
14
|
-
* }
|
|
15
|
-
* };
|
|
16
|
-
*
|
|
17
|
-
* notate(obj, 'top_level.nested.value');
|
|
18
|
-
* // 'My Value'
|
|
19
|
-
*
|
|
20
|
-
* notate(obj, 'top_level.missing.value');
|
|
21
|
-
* // undefined
|
|
22
|
-
*/
|
|
23
|
-
export declare function notate(source: any, string?: string): any;
|