proto-toolkit 1.0.1 → 1.0.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/README.md +23 -2
- package/dist/proto-toolkit.cjs.js +19 -0
- package/dist/proto-toolkit.esm.js +19 -0
- package/dist/proto-toolkit.umd.js +19 -0
- package/dist/proto-toolkit.umd.min.js +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ After importing, you can directly use the added methods on strings.
|
|
|
44
44
|
Include the script tag before your custom script:
|
|
45
45
|
|
|
46
46
|
```html
|
|
47
|
-
<script src="https://cdn.jsdelivr.net/npm/proto-toolkit/dist/proto-toolkit.umd.js"></script>
|
|
47
|
+
<script src="https://cdn.jsdelivr.net/npm/proto-toolkit/dist/proto-toolkit.umd.min.js"></script>
|
|
48
48
|
<script>
|
|
49
49
|
let name = 'Kousik Chowdhury';
|
|
50
50
|
console.log(name.mask());
|
|
@@ -57,6 +57,7 @@ Include the script tag before your custom script:
|
|
|
57
57
|
|
|
58
58
|
- `mask()`
|
|
59
59
|
- `toAbbreviatedName()`
|
|
60
|
+
- `toCapitalize()`
|
|
60
61
|
|
|
61
62
|
---
|
|
62
63
|
|
|
@@ -100,6 +101,27 @@ console.log(name.toAbbreviatedName());
|
|
|
100
101
|
K.Chowdhury;
|
|
101
102
|
```
|
|
102
103
|
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## 3. toCapitalize()
|
|
107
|
+
|
|
108
|
+
Capitalize first letter of each word.
|
|
109
|
+
|
|
110
|
+
### Example
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
import 'proto-toolkit';
|
|
114
|
+
|
|
115
|
+
let name = 'hello i am kousik';
|
|
116
|
+
console.log(name.toCapitalize());
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Output
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
Hello I Am Kousik;
|
|
123
|
+
```
|
|
124
|
+
|
|
103
125
|
## Links
|
|
104
126
|
|
|
105
127
|
**Twitter / X**
|
|
@@ -110,4 +132,3 @@ https://kousikchowdhury.in
|
|
|
110
132
|
|
|
111
133
|
**Proto-Toolkit Docs**
|
|
112
134
|
https://proto-toolkit.kousikchowdhury.in
|
|
113
|
-
|
|
@@ -48,3 +48,22 @@ function capitalize(word) {
|
|
|
48
48
|
if (!String.prototype.toAbbreviatedName) {
|
|
49
49
|
String.prototype.toAbbreviatedName = toAbbreviatedName;
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
function toCapitalize() {
|
|
53
|
+
if (typeof this !== 'string') {
|
|
54
|
+
throw new TypeError('Input must be a string');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let str = this.trim().replace(/\s+/g, ' ');
|
|
58
|
+
|
|
59
|
+
if (str.length === 0) return;
|
|
60
|
+
if (str.length <= 1) return str.toUpperCase();
|
|
61
|
+
return str
|
|
62
|
+
.split(' ')
|
|
63
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
64
|
+
.join(' ');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!String.prototype.toCapitalize) {
|
|
68
|
+
String.prototype.toCapitalize = toCapitalize;
|
|
69
|
+
}
|
|
@@ -46,3 +46,22 @@ function capitalize(word) {
|
|
|
46
46
|
if (!String.prototype.toAbbreviatedName) {
|
|
47
47
|
String.prototype.toAbbreviatedName = toAbbreviatedName;
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
function toCapitalize() {
|
|
51
|
+
if (typeof this !== 'string') {
|
|
52
|
+
throw new TypeError('Input must be a string');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let str = this.trim().replace(/\s+/g, ' ');
|
|
56
|
+
|
|
57
|
+
if (str.length === 0) return;
|
|
58
|
+
if (str.length <= 1) return str.toUpperCase();
|
|
59
|
+
return str
|
|
60
|
+
.split(' ')
|
|
61
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
62
|
+
.join(' ');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!String.prototype.toCapitalize) {
|
|
66
|
+
String.prototype.toCapitalize = toCapitalize;
|
|
67
|
+
}
|
|
@@ -52,4 +52,23 @@
|
|
|
52
52
|
String.prototype.toAbbreviatedName = toAbbreviatedName;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
function toCapitalize() {
|
|
56
|
+
if (typeof this !== 'string') {
|
|
57
|
+
throw new TypeError('Input must be a string');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let str = this.trim().replace(/\s+/g, ' ');
|
|
61
|
+
|
|
62
|
+
if (str.length === 0) return;
|
|
63
|
+
if (str.length <= 1) return str.toUpperCase();
|
|
64
|
+
return str
|
|
65
|
+
.split(' ')
|
|
66
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
67
|
+
.join(' ');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!String.prototype.toCapitalize) {
|
|
71
|
+
String.prototype.toCapitalize = toCapitalize;
|
|
72
|
+
}
|
|
73
|
+
|
|
55
74
|
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";function t(t){return t[0].toUpperCase()+t.slice(1).toLowerCase()}String.prototype.mask||(String.prototype.mask=function(){const t=this.trim();if(t.length<=4)return t;const e=t.slice(0,2),r=t.slice(-2),n=t.length-4;return e+"*".repeat(n)+r}),String.prototype.toAbbreviatedName||(String.prototype.toAbbreviatedName=function(){if("string"!=typeof this)throw new TypeError("Input must be a string");const e=this.trim().split(/\s+/).filter(Boolean);if(0===e.length)return"";if(1===e.length)return t(e[0]);const r=e.pop();return`${e.map(t=>t[0].toUpperCase()+".").join(" ")} ${t(r)}`}),String.prototype.toCapitalize||(String.prototype.toCapitalize=function(){if("string"!=typeof this)throw new TypeError("Input must be a string");let t=this.trim().replace(/\s+/g," ");if(0!==t.length)return t.length<=1?t.toUpperCase():t.split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proto-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A lightweight JavaScript utility toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/proto-toolkit.cjs.js",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"author": "Kousik Chowdhury",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
24
25
|
"rollup": "^4.59.0"
|
|
25
26
|
}
|
|
26
27
|
}
|