@mhmdhammoud/meritt-utils 1.6.1 → 1.6.3

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,125 +0,0 @@
1
- /*
2
- Author : Mhmd Hammoud https://github.com/mhmdhammoud
3
- Date : 2023-06-17
4
- Description : String manipulation
5
- Version : 1.0
6
- */
7
- class Formatter {
8
- /**
9
- * @remarks Normalizes input by removing underscores and hyphens and capitalizing the first letter of the sentence.
10
- * @param stringToBeChanged - to be formatted without underscores and hyphens
11
- * @param withWhiteSpacing - Determines if white spacing is needed in the final string or not (default: true)
12
- * @returns string
13
- * @example
14
- * ```typescript
15
- * formatter.toUpperFirst('hello world')
16
- * // => 'Hello-World'
17
- * ```
18
- * */
19
- toUpperFirst = (str: string | number): string => {
20
- if (typeof str !== 'string') throw new Error('Provide a valid string')
21
-
22
- const formattedString = str
23
- .toString()
24
- .replace(/[^a-zA-Z0-9]+/g, '-')
25
- .trim()
26
- .toLowerCase()
27
-
28
- return formattedString.charAt(0).toUpperCase() + formattedString.slice(1)
29
- }
30
-
31
- /**
32
- * @remarks normalizes input to supported path and file name format.
33
- * Changes camelCase strings to kebab-case, replaces spaces with dash and keeps underscores. *
34
- * @param str - String needed to be modified
35
- * @returns formatted string
36
- */
37
- camelToKebab = (str: string | number): string => {
38
- if (typeof str !== 'string') {
39
- throw new Error('Invalid input. Please provide a valid string.')
40
- }
41
-
42
- const STRING_DASHERIZE_REGEXP = /\s/g
43
- const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g
44
-
45
- return str
46
- .replace(STRING_DECAMELIZE_REGEXP, '$1-$2')
47
- .toLowerCase()
48
- .replace(STRING_DASHERIZE_REGEXP, '-')
49
- }
50
-
51
- /**
52
- * @remarks obfuscates email address
53
- * @param email - email address to be obfuscated
54
- * @returns obfuscated email address
55
- * @example
56
- * ```typescript
57
- * formatter.obfuscate('johndoe@email.com') // => jo*****@gmail.com
58
- * ```
59
- * */
60
- obfuscate = (email: string) => {
61
- if (typeof email !== 'string') throw new Error('Provide a valid string')
62
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
63
- if (!emailRegex.test(email))
64
- throw new Error('Provide a valid email address')
65
- const separatorIndex = email.indexOf('@')
66
- if (separatorIndex < 3) {
67
- // 'ab@gmail.com' -> '**@gmail.com'
68
- return (
69
- email.slice(0, separatorIndex).replace(/./g, '*') +
70
- email.slice(separatorIndex)
71
- )
72
- }
73
- // 'test42@gmail.com' -> 'te****@gmail.com'
74
- return (
75
- email.slice(0, 2) +
76
- email.slice(2, separatorIndex).replace(/./g, '*') +
77
- email.slice(separatorIndex)
78
- )
79
- }
80
-
81
- /**
82
- * Capitalizes the first letter of each word in a sentence and removes non-alphanumeric characters.
83
- * @param sentence - The input sentence to be processed.
84
- * @returns A new sentence with the first letter of each word capitalized and non-alphanumeric characters removed.
85
- * @example
86
- * ```typescript
87
- * const sentence = 'this is34354345a---sentence'
88
- * const newSentence = ToUpperTitle(sentence)
89
- * console.log(newSentence) // 'This Is A Sentence'
90
- * ```
91
- */
92
- toUpperTitle = (sentence: string | number): string => {
93
- if (typeof sentence !== 'string') throw new Error('Provide a valid string')
94
- if (!sentence) throw new Error('Provide a valid string')
95
-
96
- const sanitizedSentence = sentence.replace(/[^a-zA-Z\s]+/g, ' ') // Exclude numbers from the character class
97
- const words = sanitizedSentence.split(/\s+/)
98
- const capitalizedWords = words.map((word) => {
99
- return word.charAt(0).toUpperCase() + word.slice(1)
100
- })
101
-
102
- return capitalizedWords.join(' ')
103
- }
104
-
105
- /**
106
- * @remarks Generates a slug from a given string
107
- * @param title - string to be converted to slug
108
- * @returns slug
109
- * @example
110
- * ```typescript
111
- * formatter.slugify('Hello World') // => hello-world
112
- * ```
113
- * */
114
- slugify = (title: string | number): string => {
115
- if (typeof title !== 'string') throw new Error('Provide a valid string')
116
-
117
- return title
118
- .replace(/[^\w\s]/g, '') // Remove non-alphanumeric characters
119
- .replace(/\s+/g, '-') // Replace consecutive spaces with a single dash
120
- .toLowerCase()
121
- }
122
- }
123
-
124
- const formatter = new Formatter()
125
- export default formatter
@@ -1,41 +0,0 @@
1
- import imagesLoaded from 'imagesloaded'
2
- /*
3
- Author : Mustafa Halabi https://github.com/mustafahalabi
4
- Date : 2024-01-29
5
- Description : Loads images and returns a promise
6
- Version : 1.0
7
- */
8
- class ImageFull {
9
- /**
10
- * @remarks
11
- * Receives either a className or an id or an element and returns a promise that resolves when all images are loaded
12
- * @param selector - either a className or an id or an element that contains images
13
- * @example
14
- * ```ts
15
- * .image-container
16
- * #image-container
17
- * img //as an element
18
- *
19
- * Imagefull.preloadImages('.image-container').then((event) => {
20
- * do something
21
- * })
22
- * ```
23
- *
24
- * @returns Promise<ImagesLoaded | undefined>
25
- *
26
- */
27
- preloadImages = (selector: string) => {
28
- return new Promise((resolve) => {
29
- imagesLoaded(
30
- document.querySelectorAll(selector),
31
- { background: true },
32
- (event) => {
33
- resolve(event)
34
- }
35
- )
36
- })
37
- }
38
- }
39
-
40
- const imagefull = new ImageFull()
41
- export default imagefull
package/src/lib/index.ts DELETED
@@ -1,12 +0,0 @@
1
- export { default as Crypto } from './cypto'
2
- export { default as Formatter } from './formatter'
3
- export { default as Pdf } from './formatter'
4
- export { default as Colorful } from './colorful'
5
- export { default as ImageFull } from './imagefull'
6
- export { default as Logger } from './logger'
7
- export {
8
- runWithTrace,
9
- runWithTraceSync,
10
- getTraceContext,
11
- type TraceContext,
12
- } from './trace-store'