|
168 | 168 | "// Example usage:", |
169 | 169 | "console.log(countWords('Hello world! This is a test.')); // Output: 6" |
170 | 170 | ], |
171 | | - "tags": ["string", "manipulation", "word count", "count"], |
| 171 | + "tags": ["javascript", "string", "manipulation", "word count", "count"], |
172 | 172 | "author": "axorax" |
173 | 173 | }, |
174 | 174 | { |
|
182 | 182 | "// Example usage:", |
183 | 183 | "console.log(removeWhitespace('Hello world!')); // Output: 'Helloworld!'" |
184 | 184 | ], |
185 | | - "tags": ["string", "whitespace"], |
| 185 | + "tags": ["javascript", "string", "whitespace"], |
186 | 186 | "author": "axorax" |
187 | 187 | } |
188 | 188 | ] |
|
318 | 318 | "console.log(timeAgoOrAhead(new Date())); // just now", |
319 | 319 | "console.log(timeAgoOrAhead(futureDate)); // in x years" |
320 | 320 | ], |
321 | | - "tags": [ |
322 | | - "javascript", |
323 | | - "date", |
324 | | - "time", |
325 | | - "relative", |
326 | | - "future", |
327 | | - "past", |
328 | | - "utility" |
329 | | - ], |
| 321 | + "tags": ["javascript", "date", "time", "relative", "future", "past", "utility"], |
330 | 322 | "author": "Yugveer06" |
331 | 323 | } |
332 | 324 | ] |
|
529 | 521 | } |
530 | 522 | ] |
531 | 523 | }, |
532 | | -{ |
533 | | - "categoryName": "Number Formatting", |
534 | | - "snippets": [ |
535 | | - { |
536 | | - "title": "Number Formatter", |
537 | | - "description": "Formats a number with suffixes (K, M, B, etc.).", |
538 | | - "code": [ |
539 | | - "const nFormatter = (num) => {", |
540 | | - " if (!num) return;", |
541 | | - " num = parseFloat(num.toString().replace(/[^0-9.]/g, ''));", |
542 | | - " const suffixes = ['', 'K', 'M', 'B', 'T', 'P', 'E'];", |
543 | | - " let index = 0;", |
544 | | - " while (num >= 1000 && index < suffixes.length - 1) {", |
545 | | - " num /= 1000;", |
546 | | - " index++;", |
547 | | - " }", |
548 | | - " return num.toFixed(2).replace(/\\.0+$|(\\.[0-9]*[1-9])0+$/, '$1') + suffixes[index];", |
549 | | - "};", |
550 | | - "", |
551 | | - "// Usage:", |
552 | | - "console.log(nFormatter(1234567)); // Output: '1.23M'" |
553 | | - ], |
554 | | - "tags": ["javascript", "number", "format", "utility"], |
555 | | - "author": "realvishalrana" |
556 | | - } |
557 | | - ] |
558 | | -} |
559 | | - |
| 524 | + { |
| 525 | + "categoryName": "Number Formatting", |
| 526 | + "snippets": [ |
| 527 | + { |
| 528 | + "title": "Number Formatter", |
| 529 | + "description": "Formats a number with suffixes (K, M, B, etc.).", |
| 530 | + "code": [ |
| 531 | + "const nFormatter = (num) => {", |
| 532 | + " if (!num) return;", |
| 533 | + " num = parseFloat(num.toString().replace(/[^0-9.]/g, ''));", |
| 534 | + " const suffixes = ['', 'K', 'M', 'B', 'T', 'P', 'E'];", |
| 535 | + " let index = 0;", |
| 536 | + " while (num >= 1000 && index < suffixes.length - 1) {", |
| 537 | + " num /= 1000;", |
| 538 | + " index++;", |
| 539 | + " }", |
| 540 | + " return num.toFixed(2).replace(/\\.0+$|(\\.[0-9]*[1-9])0+$/, '$1') + suffixes[index];", |
| 541 | + "};", |
| 542 | + "", |
| 543 | + "// Usage:", |
| 544 | + "console.log(nFormatter(1234567)); // Output: '1.23M'" |
| 545 | + ], |
| 546 | + "tags": ["javascript", "number", "format", "utility"], |
| 547 | + "author": "realvishalrana" |
| 548 | + } |
| 549 | + ] |
| 550 | + } |
560 | 551 | ] |
0 commit comments