@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.
- package/ReleaseNotes.md +17 -1
- package/dist/__tests__/elastic-transport.test.d.ts +1 -0
- package/dist/__tests__/elastic-transport.test.js +78 -0
- package/dist/__tests__/logger.test.js +21 -0
- package/dist/lib/elastic-transport.d.ts +5 -1
- package/dist/lib/elastic-transport.js +49 -11
- package/dist/lib/logger.js +11 -6
- package/dist/types/logger.d.ts +2 -1
- package/package.json +9 -3
- package/.github/workflows/npm-publish.yml +0 -84
- package/.github/workflows/push.yml +0 -83
- package/.husky/pre-commit +0 -62
- package/.prettierrc +0 -8
- package/.prettierrc.json +0 -8
- package/ISSUES.md +0 -0
- package/eslint.config.mjs +0 -64
- package/example.env +0 -6
- package/jest.config.js +0 -13
- package/src/__tests__/colorful.test.ts +0 -77
- package/src/__tests__/formatter.test.ts +0 -96
- package/src/__tests__/logger.test.ts +0 -122
- package/src/env.d.ts +0 -9
- package/src/index.ts +0 -1
- package/src/lib/colorful.ts +0 -167
- package/src/lib/cypto.ts +0 -296
- package/src/lib/elastic-transport.ts +0 -307
- package/src/lib/formatter.ts +0 -125
- package/src/lib/imagefull.ts +0 -41
- package/src/lib/index.ts +0 -12
- package/src/lib/logger.ts +0 -590
- package/src/lib/pdf.ts +0 -25
- package/src/lib/trace-store.ts +0 -46
- package/src/types/index.ts +0 -1
- package/src/types/logger.ts +0 -66
- package/src/utilities/axios.ts +0 -4
- package/src/utilities/index.ts +0 -1
- package/tsconfig.json +0 -16
package/src/lib/formatter.ts
DELETED
|
@@ -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
|
package/src/lib/imagefull.ts
DELETED
|
@@ -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'
|