stringweaver 1.4.2 → 1.4.4

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.
@@ -1,111 +1,92 @@
1
- import {default as randomString, uuid4} from "./Factories/randomStringFactory.js";
2
1
  import interpolate from "./factories/splatESBundle.js";
3
2
  import createRegExp from "./Factories/regExpFromMultilineStringFactory.js";
4
- import createInstance from "./extensions.js";
5
- import {capitalizerFactory} from "./instanceMethods.js";
6
- const customMethods = {};
3
+ import {default as randomString, uuid4} from "./Factories/randomStringFactory.js";
4
+ import {CustomStringConstructor} from "./CTORCreator.js";
5
+ import {parseCamelcase, parseKebabCase, parseSnakeCase, ucFirst, wordsFirstUp} from "./instanceMethods.js";
7
6
  const quotingStyles = defineQuotingStyles();
7
+ const deprecatedRE = /symbol|anchor|big|blink|bold|fixed|fontsize|fontcolor|italics|link|small|strike|sup|sub/i
8
8
 
9
9
  export {
10
- customMethods,
11
- CustomStringConstructor,
12
- isNumber,
13
- isArrayOf,
14
- quotGetters4Instance,
15
- getStringValue,
16
- escapeRE,
17
- resolveTemplateString,
18
- clone,
19
- interpolate,
20
- quotingStyles,
21
- createRegExp,
10
+ capitalizerFactory, createExtendedCTOR, createRegExp, defineQuotingStyles,
11
+ deprecatedRE, getStringValue, escapeRE, infoValue, interpolate, isArrayOf, isNumber,
12
+ randomString, resolveTemplateString, retrieveQuotInfo, quotGetters4Instance, uuid4,
22
13
  };
23
14
 
24
- createExtendedCTOR(CustomStringConstructor, customMethods);
25
-
26
- function CustomStringConstructor(str, ...args) {
27
- const instance = createInstance({initialstring: resolveTemplateString(str, ...args)});
28
- Object.defineProperty( instance,
29
- `constructor`, { get() { return CustomStringConstructor; }, enumerable: false}
30
- );
31
- return Object.freeze(instance);
32
- }
33
-
34
- function resolveTemplateString(str, ...args) {
35
- return str?.raw
36
- ? String.raw({ raw: str }, ...args)
37
- : getStringValue(str).length ? str : "";
15
+ function defineQuotingStyles() {
16
+ // see https://en.wikipedia.org/wiki/Quotation_mark
17
+ const quots = {
18
+ backtick: ["`", "`"],
19
+ parentheses: [`(`, `)`],
20
+ curlyBrackets: [`{`, `}`],
21
+ curlyDoubleInward: [`”`, `“`],
22
+ curlyDouble: [`“`, `”`],
23
+ curlyDoubleEqual: [`“`, `“`],
24
+ curlyLHDouble: [`„`, `”`],
25
+ curlyLHDoubleInward: [`„`, `“`],
26
+ curlyLHSingle: [`‚`, `’`],
27
+ curlyLHSingleInward: [`‚`, `‘`],
28
+ curlySingle: [`‛`, `’`],
29
+ curlySingleEqual: [`‛`, `‛`],
30
+ curlySingleInward: [`’`, `‛`],
31
+ double: [`"`, `"`],
32
+ guillemets: [`«`, `»`],
33
+ guillemetsInward: [`»`, `«`],
34
+ guillemetsSingle: [`‹`, `›`],
35
+ guillemetsSingleInward: [`›`, `‹`],
36
+ single: [`'`, `'`],
37
+ squareBrackets: [`[`, `]`],
38
+ };
39
+ quots.re = escapeRE([...new Set(
40
+ Object.values(quots)
41
+ .filter(v => Array.isArray(v))
42
+ .flat())].join(``), "g");
43
+ return quots;
38
44
  }
39
45
 
40
- function isArrayOf(type, value, includeInstances = true) {
41
- return Array.isArray(value) && value.length > 0 && !value.find(v => checkType(type, v, includeInstances));
46
+ function escapeRE(reString, modifiers) {
47
+ return new RegExp(reString.replace(/\p{S}|\p{P}/gu, a => `\\${a}`), modifiers);
42
48
  }
43
49
 
44
- function clone(instance) {
45
- const newInstance = CustomStringConstructor(instance.value);
46
- newInstance.history = [...instance.history];
47
- return newInstance;
48
- }
49
50
 
50
51
  function getStringValue(string) {
51
52
  return string?.value || (string?.constructor === String && string) || ``;
52
53
  }
53
54
 
54
- function isNumber(value) {
55
- return value?.constructor === Number && !Number.isNaN(value);
56
- }
57
-
58
- function escapeRE(reString, modifiers) {
59
- return new RegExp(reString.replace(/\p{S}|\p{P}/gu, a => `\\${a}`), modifiers);
55
+ function isArrayOf(type, value, includeInstances = true) {
56
+ return Array.isArray(value) && value.length > 0 &&
57
+ !value.find(v => checkType(type, v, includeInstances));
60
58
  }
61
59
 
62
- function escape4RE(reString) {
63
- return reString.replace(/\p{S}|\p{P}/gu, a => `\\${a}`);
60
+ function isNumber(value) {
61
+ return value?.constructor === Number && !Number.isNaN(value);
64
62
  }
65
63
 
66
64
  function infoValue(key, infoValue) {
67
65
  return `${key} (${infoValue})`;
68
66
  }
69
67
 
70
- function getPlainValues() {
71
- const capitalizerKeys = Object.keys(capitalizerFactory());
72
- return {
73
- value: `getter/setter`,
74
- clone: `chainable getter`,
75
- notEmpty: `chainable getter|undefined`,
76
- quote: `Object. See [constructor].quoteInfo`,
77
- capitalize: `getter. Object with chainable getters: [${capitalizerKeys.join(`, `)}]`,
78
- };
68
+ function checkType(type, item, includeInstances) {
69
+ return type === String && includeInstances
70
+ ? item?.constructor !== CustomStringConstructor && item?.constructor !== type
71
+ : item?.constructor !== type;
79
72
  }
80
73
 
81
- function getSWInformation(notChainable) {
82
- const firstLines = CustomStringConstructor(decode());
83
- const plainValues = getPlainValues();
74
+ function resolveTemplateString(str, ...args) {
75
+ return str?.raw
76
+ ? String.raw({ raw: str }, ...args)
77
+ : getStringValue(str).length ? str : "";
78
+ }
84
79
 
85
- return firstLines.split(/\n/)
86
- .concat(
87
- Object.entries(Object.getOwnPropertyDescriptors(firstLines))
88
- .sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
89
- .map(([key, descriptr]) => {
90
- const isChainable = !notChainable.find(k => k === key);
91
- const isGetter = 'get' in descriptr;
92
- const isMethod = 'value' in descriptr;
93
- const isNative = key in String.prototype;
94
- const isPlainValue = !isNative && key in plainValues;
95
- const custom = key in customMethods ? ` *custom*` : ``;
96
- const getter = isGetter && isChainable ? `chainable getter${custom}` : `getter`;
97
- const method = isMethod && isChainable ? `chainable method${custom}` : `method`;
98
- const native = isNative && `${descriptr.get ? `getter` : `method`} (override)`;
80
+ function retrieveQuotInfo(instanceQuotGetters4Info, ctor) {
81
+ return Object.entries(Object.getOwnPropertyDescriptors(instanceQuotGetters4Info.value))
82
+ .sort( (a,b) => a[0].localeCompare(b[0]) )
83
+ .reduce((acc, [k,]) => {
84
+ if (k === `remove`) { return [...acc, `[instance].quote.remove (only predefined)`]; }
85
+ if (k === `custom`) { return [...acc, `[instance].quote.custom(start:string, end:string)`]; }
99
86
 
100
- switch (true) {
101
- case isPlainValue: return infoValue(key, plainValues[key]);
102
- case isNative: return infoValue(key, native);
103
- case isMethod: return infoValue(key, method);
104
- case isGetter: return infoValue(key, getter);
105
- }
106
- }
107
- )
108
- );
87
+ const val = ctor(`[instance]`).quote[k];
88
+ return [...acc, `[instance].quote.${k} ( ${val} )`];
89
+ }, []);
109
90
  }
110
91
 
111
92
  function quotGetters4Instance(instance, wrap) {
@@ -139,58 +120,38 @@ function quotGetters4Instance(instance, wrap) {
139
120
  };
140
121
  }
141
122
 
142
- function decode() {
143
- return atob`Rm9yIHRoZSByZWNvcmQ6CltjbV0gY2hhaW5hYmxlIGdldHRlcnMvbWV0aG9kcyBtb2RpZnkgdGhlIGluc3RhbmNlIHN0cmluZwpbY21dIGluZGV4T2Ygb3ZlcnJpZGVzIHJldHVybnMgW3VuZGVmaW5lZF0gaWYgbm90aGluZyB3YXMgZm91bmQgKHNvIG9uZSBjYW4gdXNlIFtsYXN0SV1pbmRleE9mKFtzb21lIHN0cmluZyB2YWx1ZV0pID8/IDAKW2NtXSBpbmNsdWRlcyBpbmZvcm1hdGlvbiBmb3IgY3VzdG9tIG1ldGhvZHMvZ2V0dGVycyBpZiBhcHBsaWNhYmxl`.replace(/\[cm]/g, `\u2714`);
144
- }
145
-
146
- function defineQuotingStyles() {
147
- // see https://en.wikipedia.org/wiki/Quotation_mark
148
- const quots = {
149
- backtick: ["`", "`"],
150
- parentheses: [`(`, `)`],
151
- curlyBrackets: [`{`, `}`],
152
- curlyDoubleInward: [`”`, `“`],
153
- curlyDouble: [`“`, `”`],
154
- curlyDoubleEqual: [`“`, `“`],
155
- curlyLHDouble: [`„`, `”`],
156
- curlyLHDoubleInward: [`„`, `“`],
157
- curlyLHSingle: [`‚`, `’`],
158
- curlyLHSingleInward: [`‚`, `‘`],
159
- curlySingle: [`‛`, `’`],
160
- curlySingleEqual: [`‛`, `‛`],
161
- curlySingleInward: [`’`, `‛`],
162
- double: [`"`, `"`],
163
- guillemets: [`«`, `»`],
164
- guillemetsInward: [`»`, `«`],
165
- guillemetsSingle: [`‹`, `›`],
166
- guillemetsSingleInward: [`›`, `‹`],
167
- single: [`'`, `'`],
168
- squareBrackets: [`[`, `]`],
169
- };
170
- const regExpValues = escape4RE([...new Set(
171
- Object.values(quots)
172
- .filter(v => Array.isArray(v))
173
- .flat())].join(``));
174
- quots.re = RegExp(`^[${regExpValues}]|[${regExpValues}]$`, "g");
175
-
176
- return quots;
177
- }
178
-
179
- function retrieveQuotInfo(instanceQuotGetters4Info, ctor) {
180
- return Object.entries(Object.getOwnPropertyDescriptors(instanceQuotGetters4Info.value))
181
- .sort( (a,b) => a[0].localeCompare(b[0]) )
182
- .reduce((acc, [k,]) => {
183
- if (k === `remove`) { return [...acc, `[instance].quote.remove (only predefined)`]; }
184
- if (k === `custom`) { return [...acc, `[instance].quote.custom(start:string, end:string)`]; }
185
-
186
- const val = ctor(`[instance]`).quote[k];
187
- return [...acc, `[instance].quote.${k} ( ${val} )`];
188
- }, []);
123
+ function capitalizerFactory(instance, wrap) {
124
+ return {
125
+ get full() {
126
+ return wrap(instance.value.toUpperCase());
127
+ },
128
+ get none() {
129
+ return wrap(instance.value.toLowerCase());
130
+ },
131
+ get camel() {
132
+ return wrap(parseCamelcase(instance.value));
133
+ },
134
+ get snake() {
135
+ return wrap(parseSnakeCase(instance.value));
136
+ },
137
+ get first() {
138
+ return wrap(ucFirst(instance.value));
139
+ },
140
+ get kebab() {
141
+ return wrap(parseKebabCase(instance.value));
142
+ },
143
+ get words() {
144
+ return wrap(wordsFirstUp(instance.value));
145
+ },
146
+ get dashed() {
147
+ return wrap(parseKebabCase(instance.value));
148
+ },
149
+ }
189
150
  }
190
151
 
191
152
  function createExtendedCTOR(ctor, customMethods) {
192
153
  const quoteInfo = retrieveQuotInfo(quotGetters4Instance(ctor()), ctor);
193
- const swInfo = getSWInformation(`constructor,history,indexOf,toString,value,valueOf,empty`.split(`,`));
154
+ const swInfo = () => getSWInformation(`constructor,history,indexOf,toString,value,valueOf,empty`.split(`,`), customMethods);
194
155
  Symbol.toSB = Symbol(`toStringBuilder`);
195
156
  Object.defineProperty(
196
157
  String.prototype,
@@ -201,7 +162,6 @@ function createExtendedCTOR(ctor, customMethods) {
201
162
  }
202
163
  );
203
164
 
204
-
205
165
  Object.defineProperties(ctor, {
206
166
  create: {
207
167
  get() { return ctor(); },
@@ -223,18 +183,18 @@ function createExtendedCTOR(ctor, customMethods) {
223
183
  return `addCustom: the property "${name}" exists and can not be redefined`;
224
184
  }
225
185
 
226
- if (name?.constructor === String && method?.constructor === Function && method.length > 0) {
186
+ if (typeof name === `string` && typeof method === `function` && method.length > 0) {
227
187
  customMethods[name] = {method, enumerable, isGetter};
228
188
  return `addCustom: the ${isGetter ? `getter` : `method`} named "${name}" is added`;
229
189
  }
230
190
  }
231
191
  },
232
- info: { value: swInfo, },
192
+ info: { get() { return swInfo(); } },
233
193
  keys: {
234
194
  get() {
235
195
  return Object.keys(Object.getOwnPropertyDescriptors(CustomStringConstructor``))
236
196
  .sort( (a,b) => a.localeCompare(b) )
237
- .map(v => !/constructor|toString|valueOf/.test(v) && v in customMethods ? `${v} *custom*` : v);
197
+ .map(v => !/constructor|toString|valueOf/.test(v) && Object.hasOwn(customMethods, v) ? `${v} *custom*` : v);
238
198
  }
239
199
  },
240
200
  quoteInfo: { value: quoteInfo },
@@ -250,8 +210,51 @@ function createExtendedCTOR(ctor, customMethods) {
250
210
  return;
251
211
  }
252
212
 
253
- function checkType(type, item, includeInstances) {
254
- return type === String && includeInstances
255
- ? item?.constructor !== CustomStringConstructor && item?.constructor !== type
256
- : item?.constructor !== type;
213
+ function getSWInformation(notChainable, customMethods) {
214
+ const firstLines = CustomStringConstructor(getInfoPrefix());
215
+ const plainValues = getPlainValues();
216
+
217
+ return firstLines.split(/\n/)
218
+ .concat(
219
+ Object.entries(Object.getOwnPropertyDescriptors(firstLines))
220
+ .sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
221
+ .map(([key, descriptr]) => {
222
+ const isChainable = !notChainable.find(k => k === key);
223
+ const isGetter = Object.hasOwn(descriptr, `get`);
224
+ const isMethod = Object.hasOwn(descriptr, `value`);
225
+ const isNative = Object.hasOwn(String.prototype, key);
226
+ const isPlainValue = !isNative && Object.hasOwn(plainValues, key);
227
+ const custom = Object.hasOwn(customMethods, key) ? ` *custom*` : ``;
228
+ const getter = isGetter && isChainable ? `chainable getter${custom}` : `getter`;
229
+ const method = isMethod && isChainable ? `chainable method${custom}` : `method`;
230
+ const native = isNative && `${descriptr.get ? `getter` : `method`} (override)`;
231
+
232
+ switch (true) {
233
+ case isPlainValue: return infoValue(key, plainValues[key]);
234
+ case isNative: return infoValue(key, native);
235
+ case isMethod: return infoValue(key, method);
236
+ case isGetter: return infoValue(key, getter);
237
+ }
238
+ }
239
+ )
240
+ );
241
+ }
242
+
243
+ function getPlainValues() {
244
+ const capitalizerKeys = Object.keys(capitalizerFactory());
245
+ return {
246
+ value: `getter/setter`,
247
+ clone: `chainable getter`,
248
+ notEmpty: `chainable getter|undefined`,
249
+ quote: `Object. See [constructor].quoteInfo`,
250
+ capitalize: `getter. Object with chainable getters: [${capitalizerKeys.join(`, `)}]`,
251
+ };
252
+ }
253
+
254
+ function getInfoPrefix() {
255
+ return atob(
256
+ `Rm9yIHRoZSByZWNvcmQ6CltjbV0gY2hhaW5hYmxlIGdldHRlcnMvbWV0aG9kcyBtb2RpZnkgdGhlIGluc3RhbmNlIHN0cmluZwpbY21d`+
257
+ `IGluZGV4T2Ygb3ZlcnJpZGVzIHJldHVybnMgW3VuZGVmaW5lZF0gaWYgbm90aGluZyB3YXMgZm91bmQgKHNvIG9uZSBjYW4gdXNlIFtsYXN0`+
258
+ `SV1pbmRleE9mKFtzb21lIHN0cmluZyB2YWx1ZV0pID8/IDAKW2NtXSBpbmNsdWRlcyBpbmZvcm1hdGlvbiBmb3IgY3VzdG9tIG1ldGhv`+
259
+ `ZHMvZ2V0dGVycyBpZiBhcHBsaWNhYmxl`).replace(/\[cm]/g, `\u2714`);
257
260
  }
@@ -0,0 +1,170 @@
1
+ import {
2
+ format,
3
+ ucFirst,
4
+ truncate,
5
+ trimAll,
6
+ replaceWords,
7
+ indexOf,
8
+ lastIndexOf,
9
+ insert,
10
+ append,
11
+ prefix,
12
+ getStringValue,
13
+ quotGetters,
14
+ surroundWith,
15
+ parseCamelcase,
16
+ wordsFirstUp,
17
+ parseKebabCase,
18
+ parseSnakeCase,
19
+ customMethods,
20
+ isNumber,
21
+ clone,
22
+ trim,
23
+ } from "./instanceMethods.js";
24
+
25
+ import { capitalizerFactory, deprecatedRE } from "./helpers.js";
26
+
27
+ export default instanceCreator;
28
+
29
+ function instanceCreator({initialstring} = {}) {
30
+ let customStringExtensions = Object.create(null, { });
31
+ let instance = new Proxy(customStringExtensions, getTraps(customStringExtensions));
32
+ let actualValue = getStringValue(initialstring);
33
+ let history = [actualValue];
34
+ const defaultDescriptorProps = {configurable: false, enumerable: false};
35
+
36
+ Object.defineProperties( customStringExtensions, {
37
+ // methods
38
+ append: { ...defaultDescriptorProps, value(...strings) { return wrap(append(actualValue, ...strings)); } },
39
+ enclose: { ...defaultDescriptorProps, value(start, end) { return wrap(surroundWith(actualValue, start, end)); } },
40
+ format: { ...defaultDescriptorProps, value(...tokens) { return wrap(format(actualValue, ...tokens)); } },
41
+ indexOf: { ...defaultDescriptorProps, value(str) { return indexOf(actualValue, str); } },
42
+ interpolate: { ...defaultDescriptorProps, value(...tokens) { return wrap(format(actualValue, ...tokens)); } },
43
+ insert: { ...defaultDescriptorProps, value({ value, values, at } = {}) {
44
+ return wrap(insert(actualValue, { value, values, at }));
45
+ }
46
+ },
47
+ lastIndexOf: { ...defaultDescriptorProps, value(str) { return lastIndexOf(actualValue, str); } },
48
+ prefix: { ...defaultDescriptorProps, value(...strings) { return wrap(prefix(actualValue, ...strings)); } },
49
+ replaceWords: { ...defaultDescriptorProps, value({caseSensitive = false, replacements = {}} = {}) {
50
+ return wrap(replaceWords(actualValue, { replacements: replacements ?? {}, caseSensitive }));
51
+ } },
52
+ toString: { ...defaultDescriptorProps, value() { return actualValue; } },
53
+ trim: {...defaultDescriptorProps, value(start, end) { return wrap(trim(actualValue, start, end)); } },
54
+ truncate: { ...defaultDescriptorProps, value({at, html = false, wordBoundary = false} = {}) {
55
+ return wrap(truncate(actualValue, {at, html, wordBoundary})); } },
56
+ valueOf: { ...defaultDescriptorProps, value() { return actualValue; } },
57
+ undoLast: { ...defaultDescriptorProps, value(nSteps) { return undoSteps(nSteps); } },
58
+
59
+ // getters
60
+ camelCase: { ...defaultDescriptorProps, get() { return wrap(parseCamelcase(getStringValue(actualValue))); } },
61
+ capitalize: { ...defaultDescriptorProps, value: capitalizerFactory(instance, wrap) },
62
+ clone: { ...defaultDescriptorProps, get() { return clone(instance, customMethods); } },
63
+ firstUp: { ...defaultDescriptorProps, get() { return wrap(ucFirst(getStringValue(actualValue))); } },
64
+ history: { ...defaultDescriptorProps, get() { return history; }, set(value) { history = value; } },
65
+ empty: { ...defaultDescriptorProps, get() { return actualValue.length < 1; } },
66
+ notEmpty: { ...defaultDescriptorProps, get() { return actualValue.length < 1 ? undefined: instance; } },
67
+ kebabCase: { ...defaultDescriptorProps, get() { return wrap(parseKebabCase(getStringValue(actualValue))); } },
68
+ quote: quotGetters(instance, wrap),
69
+ snakeCase: { ...defaultDescriptorProps, get() { return wrap(parseSnakeCase(getStringValue(actualValue))); } },
70
+ trimAll: { ...defaultDescriptorProps, get() { return wrap(trimAll(actualValue)); } },
71
+ trimAllKeepLF: { ...defaultDescriptorProps, get() { return wrap(trimAll(actualValue, true)); } },
72
+ undoAll: { ...defaultDescriptorProps, get() { return undoAll(); } },
73
+ undo: { ...defaultDescriptorProps, get() { return undoLast(); } },
74
+ wordsUCFirst: { ...defaultDescriptorProps, get() { return wrap(wordsFirstUp(getStringValue(actualValue))); } },
75
+ value: { ...defaultDescriptorProps,
76
+ get() { return actualValue; },
77
+ set(value) {
78
+ const nwValue = getStringValue(value);
79
+ if (nwValue.length) {
80
+ actualValue = nwValue;
81
+ history.push(nwValue);
82
+ }
83
+ }
84
+ },
85
+ });
86
+
87
+ injectCustomMethods(customMethods);
88
+
89
+ return instance;
90
+
91
+ function getTraps(customExtensions) {
92
+ return {
93
+ get( target, key ) {
94
+ switch(true) {
95
+ case key === Symbol.for("myType"): return `stringWeaver instance (Proxy)`;
96
+ case Object.hasOwn(customExtensions, key): return customExtensions[key];
97
+ case canWrapNative(String(key)): return wrapNative(key);
98
+ default: return wrapNative(key);
99
+ }
100
+ },
101
+ };
102
+ }
103
+
104
+ function canWrapNative(key) {
105
+ return !deprecatedRE.test(key) && Object.hasOwn(String.prototype, key);
106
+ }
107
+
108
+ function wrapNative(key) {
109
+ return typeof actualValue[key] === `function`
110
+ ? function(...args) {
111
+ const result = actualValue[key](...args);
112
+ return result?.constructor === String ? wrap(actualValue[key](...args)) : result;
113
+ }
114
+ : actualValue[key];
115
+ }
116
+
117
+ function undoAll() {
118
+ while (history.length > 1) { history.pop(); }
119
+ actualValue = history.at(-1);
120
+ return wrap(actualValue, false);
121
+ }
122
+
123
+ function undoSteps(steps) {
124
+ if (!isNumber(steps)) {
125
+ return wrap(actualValue, false);
126
+ }
127
+
128
+ const historyLen = history.length;
129
+
130
+ if (steps >= historyLen || steps < 1) {
131
+ history = history.slice(0, 1);
132
+ actualValue = history.at(-1);
133
+ return wrap(history.at(-1), false);
134
+ }
135
+
136
+ history = history.slice(0, historyLen - steps);
137
+
138
+ actualValue = history.at(-1);
139
+ return wrap(actualValue, false);
140
+ }
141
+
142
+ function undoLast() {
143
+ if (history.length === 1) {
144
+ return wrap(history[0]);
145
+ }
146
+
147
+ history.pop();
148
+ actualValue = history.at(-1);
149
+ return wrap(actualValue, false);
150
+ }
151
+
152
+ function wrap(result, pushHistory = true) {
153
+ const changed = actualValue !== result;
154
+ changed && pushHistory && history.push(result);
155
+ actualValue = result;
156
+ return instance;
157
+ }
158
+
159
+ function injectCustomMethods(customMethods) {
160
+ Object.entries(customMethods).forEach(([methodName, methodContainer]) => {
161
+ const {enumerable, method, isGetter} = methodContainer;
162
+ const configurable = false
163
+ const descriptor = isGetter
164
+ ? { get() { return wrap(method(instance).value); }, enumerable, configurable }
165
+ : { value(...args) { return wrap(method(instance, ...args).value); }, enumerable, configurable };
166
+
167
+ Object.defineProperty(customStringExtensions, methodName, descriptor);
168
+ });
169
+ }
170
+ }
@@ -1,13 +1,9 @@
1
+ import { customMethods, clone, } from "./CTORCreator.js";
2
+
1
3
  import {
2
- isArrayOf,
3
- isNumber,
4
- quotGetters4Instance as quotGetters,
5
- getStringValue,
6
- escapeRE,
7
- customMethods,
8
- interpolate,
9
- createRegExp as $RE,
10
- clone } from "./genericMethods.js";
4
+ createRegExp as $RE, getStringValue, isArrayOf, interpolate,
5
+ isNumber, escapeRE, quotGetters4Instance as quotGetters,
6
+ } from "./helpers.js";
11
7
 
12
8
  export {
13
9
  format,
@@ -30,7 +26,6 @@ export {
30
26
  surroundWith,
31
27
  customMethods,
32
28
  clone,
33
- capitalizerFactory,
34
29
  trim,
35
30
  };
36
31
 
@@ -215,32 +210,3 @@ function append(string, ...strings2Append) {
215
210
 
216
211
  return getStringValue(string);
217
212
  }
218
-
219
- function capitalizerFactory(instance, wrap) {
220
- return {
221
- get full() {
222
- return wrap(instance.value.toUpperCase());
223
- },
224
- get none() {
225
- return wrap(instance.value.toLowerCase());
226
- },
227
- get camel() {
228
- return wrap(parseCamelcase(instance.value));
229
- },
230
- get snake() {
231
- return wrap(parseSnakeCase(instance.value));
232
- },
233
- get first() {
234
- return wrap(ucFirst(instance.value));
235
- },
236
- get kebab() {
237
- return wrap(parseKebabCase(instance.value));
238
- },
239
- get words() {
240
- return wrap(wordsFirstUp(instance.value));
241
- },
242
- get dashed() {
243
- return wrap(parseKebabCase(instance.value));
244
- },
245
- }
246
- }