@mythpe/quasar-ui-qui 0.1.84 → 0.1.86
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/package.json +1 -3
- package/src/components/form/MMobile.vue +23 -2
- package/src/types/myth-api.ts +1 -1
- package/src/utils/Str.ts +9 -8
- package/src/utils/copy_pluralize.js +241 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mythpe/quasar-ui-qui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.86",
|
|
4
4
|
"description": "MyTh Quasar UI Kit App Extension",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "MyTh Ahmed Faiz",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"axios": "^1.7.8",
|
|
34
34
|
"change-case": "^5.4.4",
|
|
35
35
|
"ckeditor5": "^43.3.1",
|
|
36
|
-
"pluralize": "^8.0.0",
|
|
37
36
|
"qs": "^6.13.1",
|
|
38
37
|
"radash": "^12.1.0",
|
|
39
38
|
"typed.js": "^2.1.0",
|
|
@@ -50,7 +49,6 @@
|
|
|
50
49
|
"@rollup/plugin-replace": "^6.0.1",
|
|
51
50
|
"@types/express": "^5.0.0",
|
|
52
51
|
"@types/node": "^22.10.1",
|
|
53
|
-
"@types/pluralize": "^0.0.33",
|
|
54
52
|
"@typescript-eslint/eslint-plugin": "^7.16.0",
|
|
55
53
|
"@typescript-eslint/parser": "^7.16.0",
|
|
56
54
|
"autoprefixer": "^10.4.20",
|
|
@@ -11,13 +11,26 @@
|
|
|
11
11
|
setup
|
|
12
12
|
>
|
|
13
13
|
import type { MInputProps as Props, MInputSlots } from '../../types'
|
|
14
|
-
import { useTemplateRef } from 'vue'
|
|
14
|
+
import { computed, toValue, useTemplateRef } from 'vue'
|
|
15
15
|
import MInput from './MInput.vue'
|
|
16
16
|
import { useMyth } from '../../composable'
|
|
17
17
|
|
|
18
18
|
const { props: pluginOptions, mobileRule: mobile } = useMyth()
|
|
19
19
|
const modelValue = defineModel<Props['modelValue']>({ required: !1, default: undefined })
|
|
20
20
|
const input = useTemplateRef<InstanceType<typeof MInput>>('input')
|
|
21
|
+
const mobileLength = computed(() => {
|
|
22
|
+
const final = toValue(mobile)
|
|
23
|
+
if (typeof final === 'function') {
|
|
24
|
+
return final(modelValue.value)
|
|
25
|
+
}
|
|
26
|
+
if (final === !0) {
|
|
27
|
+
return 10
|
|
28
|
+
}
|
|
29
|
+
if (!final) {
|
|
30
|
+
return undefined
|
|
31
|
+
}
|
|
32
|
+
return parseInt(final?.toString() || '0') || undefined
|
|
33
|
+
})
|
|
21
34
|
defineExpose<{ input: typeof input }>({ input })
|
|
22
35
|
defineOptions({
|
|
23
36
|
name: 'MMobile',
|
|
@@ -29,7 +42,15 @@ defineOptions({
|
|
|
29
42
|
<MInput
|
|
30
43
|
ref="input"
|
|
31
44
|
v-model="modelValue"
|
|
32
|
-
v-bind="{
|
|
45
|
+
v-bind="{
|
|
46
|
+
type: 'tel',
|
|
47
|
+
mobile: typeof mobile === 'function' ? mobile(modelValue) : (
|
|
48
|
+
mobile !== !1 && mobile !== undefined && mobile !== null
|
|
49
|
+
),
|
|
50
|
+
maxlength: mobileLength,
|
|
51
|
+
...pluginOptions.mobile as any,
|
|
52
|
+
...$attrs
|
|
53
|
+
}"
|
|
33
54
|
>
|
|
34
55
|
<template
|
|
35
56
|
v-for="(_,slot) in $slots as Readonly<MInputSlots>"
|
package/src/types/myth-api.ts
CHANGED
package/src/utils/Str.ts
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* Github: https://github.com/mythpe
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
// import { plural as pluralCase, singular as singularCase } from '
|
|
9
|
+
// import { plural as pluralCase, singular as singularCase } from '__pluralize'
|
|
10
|
+
import __pluralize from './copy_pluralize'
|
|
10
11
|
import { camelCase, capitalCase, dotCase, kebabCase, pascalCase, snakeCase } from 'change-case'
|
|
11
|
-
|
|
12
|
+
// console.log(__pluralize.plural())
|
|
12
13
|
export const Str = {
|
|
13
14
|
/**
|
|
14
15
|
* Str vue3
|
|
@@ -92,14 +93,14 @@ export const Str = {
|
|
|
92
93
|
return string ? dotCase(string?.toString() || '') : ''
|
|
93
94
|
},
|
|
94
95
|
pluralize (string?: unknown): string {
|
|
95
|
-
console.log(string)
|
|
96
|
-
|
|
97
|
-
return ''
|
|
96
|
+
// console.log(string)
|
|
97
|
+
return string ? __pluralize.plural(string?.toString() || '') : ''
|
|
98
|
+
// return ''
|
|
98
99
|
},
|
|
99
100
|
singular (string?: unknown): string {
|
|
100
|
-
console.log(string)
|
|
101
|
-
|
|
102
|
-
return ''
|
|
101
|
+
// console.log(string)
|
|
102
|
+
return string ? __pluralize.singular(string?.toString() || '') : ''
|
|
103
|
+
// return ''
|
|
103
104
|
},
|
|
104
105
|
flipChoice (data: Record<any, any>) {
|
|
105
106
|
const f: Record<any, any> = {}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
|
|
6
|
+
// __pluralize.js
|
|
7
|
+
|
|
8
|
+
// Rule storage - __pluralize and singularize need to be run sequentially,
|
|
9
|
+
// while other rules can be optimized using an object for instant lookups.
|
|
10
|
+
const pluralRules = []
|
|
11
|
+
const singularRules = []
|
|
12
|
+
const uncountables = {}
|
|
13
|
+
const irregularPlurals = {}
|
|
14
|
+
const irregularSingles = {}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sanitize a pluralization rule to a usable regular expression.
|
|
18
|
+
* @param {(RegExp|string)} rule
|
|
19
|
+
* @return {RegExp}
|
|
20
|
+
*/
|
|
21
|
+
function sanitizeRule (rule) {
|
|
22
|
+
return typeof rule === 'string' ? new RegExp(`^${rule}$`, 'i') : rule
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Pass in a word token to produce a function that can replicate the case on another word.
|
|
27
|
+
* @param {string} word
|
|
28
|
+
* @param {string} token
|
|
29
|
+
* @return {string}
|
|
30
|
+
*/
|
|
31
|
+
function restoreCase (word, token) {
|
|
32
|
+
if (word === token) return token
|
|
33
|
+
if (word === word.toLowerCase()) return token.toLowerCase()
|
|
34
|
+
if (word === word.toUpperCase()) return token.toUpperCase()
|
|
35
|
+
if (word[0] === word[0].toUpperCase()) {
|
|
36
|
+
return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase()
|
|
37
|
+
}
|
|
38
|
+
return token.toLowerCase()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Interpolate a regexp string.
|
|
43
|
+
* @param {string} str
|
|
44
|
+
* @param {Array} args
|
|
45
|
+
* @return {string}
|
|
46
|
+
*/
|
|
47
|
+
function interpolate (str, args) {
|
|
48
|
+
return str.replace(/\$(\d{1,2})/g, (match, index) => args[index] || '')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Replace a word using a rule.
|
|
53
|
+
* @param {string} word
|
|
54
|
+
* @param {Array} rule
|
|
55
|
+
* @return {string}
|
|
56
|
+
*/
|
|
57
|
+
function replace (word, rule) {
|
|
58
|
+
return word.replace(rule[0], (match, ...args) => {
|
|
59
|
+
const result = interpolate(rule[1], args)
|
|
60
|
+
return match === '' ? restoreCase(word[args[args.length - 2] - 1], result) : restoreCase(match, result)
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Sanitize a word by passing in the word and sanitization rules.
|
|
66
|
+
* @param {string} token
|
|
67
|
+
* @param {string} word
|
|
68
|
+
* @param {Array} rules
|
|
69
|
+
* @return {string}
|
|
70
|
+
*/
|
|
71
|
+
function sanitizeWord (token, word, rules) {
|
|
72
|
+
if (!token.length || uncountables.hasOwnProperty(token)) return word
|
|
73
|
+
|
|
74
|
+
for (let i = rules.length - 1; i >= 0; i--) {
|
|
75
|
+
const rule = rules[i]
|
|
76
|
+
if (rule[0].test(word)) return replace(word, rule)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return word
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Replace a word with the updated word.
|
|
84
|
+
* @param {Object} replaceMap
|
|
85
|
+
* @param {Object} keepMap
|
|
86
|
+
* @param {Array} rules
|
|
87
|
+
* @return {Function}
|
|
88
|
+
*/
|
|
89
|
+
function replaceWord (replaceMap, keepMap, rules) {
|
|
90
|
+
return function (word) {
|
|
91
|
+
const token = word.toLowerCase()
|
|
92
|
+
|
|
93
|
+
if (keepMap.hasOwnProperty(token)) return restoreCase(word, token)
|
|
94
|
+
if (replaceMap.hasOwnProperty(token)) return restoreCase(word, replaceMap[token])
|
|
95
|
+
|
|
96
|
+
return sanitizeWord(token, word, rules)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Check if a word is part of the map.
|
|
102
|
+
*/
|
|
103
|
+
function checkWord (replaceMap, keepMap, rules) {
|
|
104
|
+
return function (word) {
|
|
105
|
+
const token = word.toLowerCase()
|
|
106
|
+
if (keepMap.hasOwnProperty(token)) return true
|
|
107
|
+
if (replaceMap.hasOwnProperty(token)) return false
|
|
108
|
+
return sanitizeWord(token, token, rules) === token
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Pluralize or singularize a word based on the passed in count.
|
|
114
|
+
* @param {string} word The word to __pluralize
|
|
115
|
+
* @param {number} count How many of the word exist
|
|
116
|
+
* @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
|
|
117
|
+
* @return {string}
|
|
118
|
+
*/
|
|
119
|
+
function __pluralize (word, count, inclusive) {
|
|
120
|
+
const pluralized = count === 1 ? __pluralize.singular(word) : __pluralize.plural(word)
|
|
121
|
+
return (inclusive ? `${count} ` : '') + pluralized
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Attach methods to __pluralize function
|
|
125
|
+
__pluralize.plural = replaceWord(irregularSingles, irregularPlurals, pluralRules)
|
|
126
|
+
__pluralize.isPlural = checkWord(irregularSingles, irregularPlurals, pluralRules)
|
|
127
|
+
__pluralize.singular = replaceWord(irregularPlurals, irregularSingles, singularRules)
|
|
128
|
+
__pluralize.isSingular = checkWord(irregularPlurals, irregularSingles, singularRules)
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Add a pluralization rule to the collection.
|
|
132
|
+
* @param {(string|RegExp)} rule
|
|
133
|
+
* @param {string} replacement
|
|
134
|
+
*/
|
|
135
|
+
__pluralize.addPluralRule = function (rule, replacement) {
|
|
136
|
+
pluralRules.push([sanitizeRule(rule), replacement])
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Add a singularization rule to the collection.
|
|
141
|
+
* @param {(string|RegExp)} rule
|
|
142
|
+
* @param {string} replacement
|
|
143
|
+
*/
|
|
144
|
+
__pluralize.addSingularRule = function (rule, replacement) {
|
|
145
|
+
singularRules.push([sanitizeRule(rule), replacement])
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Add an uncountable word rule.
|
|
150
|
+
* @param {(string|RegExp)} word
|
|
151
|
+
*/
|
|
152
|
+
__pluralize.addUncountableRule = function (word) {
|
|
153
|
+
if (typeof word === 'string') {
|
|
154
|
+
uncountables[word.toLowerCase()] = true
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
__pluralize.addPluralRule(word, '$0')
|
|
158
|
+
__pluralize.addSingularRule(word, '$0')
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Add an irregular word definition.
|
|
163
|
+
* @param {string} single
|
|
164
|
+
* @param {string} plural
|
|
165
|
+
*/
|
|
166
|
+
__pluralize.addIrregularRule = function (single, plural) {
|
|
167
|
+
const pluralLower = plural.toLowerCase()
|
|
168
|
+
const singleLower = single.toLowerCase()
|
|
169
|
+
irregularSingles[singleLower] = pluralLower
|
|
170
|
+
irregularPlurals[pluralLower] = singleLower
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// Irregular rules
|
|
174
|
+
[
|
|
175
|
+
['I', 'we'], ['me', 'us'], ['he', 'they'], ['she', 'they'], ['them', 'them'],
|
|
176
|
+
['myself', 'ourselves'], ['yourself', 'yourselves'], ['itself', 'themselves'],
|
|
177
|
+
['herself', 'themselves'], ['himself', 'themselves'], ['themself', 'themselves'],
|
|
178
|
+
['is', 'are'], ['was', 'were'], ['has', 'have'], ['this', 'these'], ['that', 'those'],
|
|
179
|
+
['echo', 'echoes'], ['dingo', 'dingoes'], ['volcano', 'volcanoes'], ['tornado', 'tornadoes'],
|
|
180
|
+
['torpedo', 'torpedoes'], ['genus', 'genera'], ['viscus', 'viscera'], ['stigma', 'stigmata'],
|
|
181
|
+
['stoma', 'stomata'], ['dogma', 'dogmata'], ['lemma', 'lemmata'], ['schema', 'schemata'],
|
|
182
|
+
['anathema', 'anathemata'], ['ox', 'oxen'], ['axe', 'axes'], ['die', 'dice'], ['yes', 'yeses'],
|
|
183
|
+
['foot', 'feet'], ['eave', 'eaves'], ['goose', 'geese'], ['tooth', 'teeth'], ['quiz', 'quizzes'],
|
|
184
|
+
['human', 'humans'], ['proof', 'proofs'], ['carve', 'carves'], ['valve', 'valves'],
|
|
185
|
+
['looey', 'looies'], ['thief', 'thieves'], ['groove', 'grooves'], ['pickaxe', 'pickaxes'],
|
|
186
|
+
['passerby', 'passersby']
|
|
187
|
+
].forEach(([single, plural]) => __pluralize.addIrregularRule(single, plural));
|
|
188
|
+
|
|
189
|
+
// Pluralization rules
|
|
190
|
+
[
|
|
191
|
+
[/s?$/i, 's'], [/[^\u0000-\u007F]$/i, '$0'], [/([^aeiou]ese)$/i, '$1'],
|
|
192
|
+
[/(ax|test)is$/i, '$1es'], [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, '$1es'],
|
|
193
|
+
[/(e[mn]u)s?$/i, '$1s'], [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, '$1'],
|
|
194
|
+
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1i'],
|
|
195
|
+
[/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'], [/(seraph|cherub)(?:im)?$/i, '$1im'],
|
|
196
|
+
[/(her|at|gr)o$/i, '$1oes'],
|
|
197
|
+
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, '$1a'],
|
|
198
|
+
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, '$1a'],
|
|
199
|
+
[/sis$/i, 'ses'], [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, '$1$2ves'],
|
|
200
|
+
[/([^aeiouy]|qu)y$/i, '$1ies'], [/([^ch][ieo][ln])ey$/i, '$1ies'],
|
|
201
|
+
[/(x|ch|ss|sh|zz)$/i, '$1es'], [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, '$1ices'],
|
|
202
|
+
[/\b((?:tit)?m|l)(?:ice|ouse)$/i, '$1ice'], [/(pe)(?:rson|ople)$/i, '$1ople'],
|
|
203
|
+
[/(child)(?:ren)?$/i, '$1ren'], [/eaux$/i, '$0'], [/m[ae]n$/i, 'men'], ['thou', 'you']
|
|
204
|
+
].forEach(([rule, replacement]) => __pluralize.addPluralRule(rule, replacement));
|
|
205
|
+
|
|
206
|
+
// Singularization rules
|
|
207
|
+
[
|
|
208
|
+
[/s$/i, ''], [/(ss)$/i, '$1'], [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
|
|
209
|
+
[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'], [/ies$/i, 'y'],
|
|
210
|
+
[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, '$1ie'],
|
|
211
|
+
[/\b(mon|smil)ies$/i, '$1ey'], [/\b((?:tit)?m|l)ice$/i, '$1ouse'],
|
|
212
|
+
[/(seraph|cherub)im$/i, '$1'], [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, '$1'],
|
|
213
|
+
[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, '$1sis'],
|
|
214
|
+
[/(movie|twelve|abuse|e[mn]u)s$/i, '$1'], [/(test)(?:is|es)$/i, '$1is'],
|
|
215
|
+
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1us'],
|
|
216
|
+
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, '$1um'],
|
|
217
|
+
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, '$1on'],
|
|
218
|
+
[/(alumn|alg|vertebr)ae$/i, '$1a'], [/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
|
|
219
|
+
[/(matr|append)ices$/i, '$1ix'], [/(pe)(rson|ople)$/i, '$1rson'], [/(child)ren$/i, '$1'],
|
|
220
|
+
[/(eau)x?$/i, '$1'], [/men$/i, 'man']
|
|
221
|
+
].forEach(([rule, replacement]) => __pluralize.addSingularRule(rule, replacement));
|
|
222
|
+
|
|
223
|
+
// Uncountable rules
|
|
224
|
+
[
|
|
225
|
+
'adulthood', 'advice', 'agenda', 'aid', 'aircraft', 'alcohol', 'ammo', 'analytics',
|
|
226
|
+
'anime', 'athletics', 'audio', 'bison', 'blood', 'bream', 'buffalo', 'butter',
|
|
227
|
+
'carp', 'cash', 'chassis', 'chess', 'clothing', 'cod', 'commerce', 'cooperation',
|
|
228
|
+
'corps', 'debris', 'diabetes', 'digestion', 'elk', 'energy', 'equipment',
|
|
229
|
+
'excretion', 'expertise', 'firmware', 'flounder', 'fun', 'gallows', 'garbage',
|
|
230
|
+
'graffiti', 'hardware', 'headquarters', 'health', 'herpes', 'highjinks', 'homework',
|
|
231
|
+
'housework', 'information', 'jeans', 'justice', 'kudos', 'labour', 'literature',
|
|
232
|
+
'machinery', 'mackerel', 'mail', 'media', 'mews', 'moose', 'music', 'mud', 'manga',
|
|
233
|
+
'news', 'only', 'personnel', 'pike', 'plankton', 'pliers', 'police', 'pollution',
|
|
234
|
+
'premises', 'rain', 'research', 'rice', 'salmon', 'scissors', 'series', 'sewage',
|
|
235
|
+
'shambles', 'shrimp', 'software', 'species', 'staff', 'swine', 'tennis', 'traffic',
|
|
236
|
+
'transportation', 'trout', 'tuna', 'wealth', 'welfare', 'whiting', 'wildebeest',
|
|
237
|
+
'wildlife', 'you', /pok[eé]mon$/i, /[^aeiou]ese$/i, /deer$/i, /fish$/i,
|
|
238
|
+
/measles$/i, /o[iu]s$/i, /pox$/i, /sheep$/i
|
|
239
|
+
].forEach(__pluralize.addUncountableRule)
|
|
240
|
+
|
|
241
|
+
export default __pluralize
|