From 99f3bfe0a7f936470b50fe86b5f168be6b213428 Mon Sep 17 00:00:00 2001 From: Pranav Date: Wed, 27 Nov 2024 16:57:12 -0800 Subject: [PATCH 1/5] feat: Add a util for splitting name --- package.json | 2 +- src/helpers.ts | 39 +++++++++++ test/helpers.test.ts | 33 ++++++++- yarn.lock | 162 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 234 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fd85384..58df1e5 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "analyze": "size-limit --why", "docs": "typedoc --theme default --out docs ./src" }, - "peerDependencies": {}, "prettier": { "printWidth": 80, "semi": true, @@ -44,6 +43,7 @@ ], "devDependencies": { "@size-limit/preset-small-lib": "^7.0.8", + "@types/jest": "^29.5.14", "husky": "^8.0.1", "size-limit": "^8.0.0", "tsdx": "^0.14.1", diff --git a/src/helpers.ts b/src/helpers.ts index 8660c8e..d676ded 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -150,3 +150,42 @@ export const fileNameWithEllipsis = ( return `${name.slice(0, maxLength)}${ellipsis}${extension}`; }; + +/** + * @name splitName + * @description Splits a full name into firstName and lastName + * @param {string} name - Full name of the user + * @returns {Object} Object with firstName and lastName + * @example + * splitName('Mary Jane Smith') // { firstName: 'Mary Jane', lastName: 'Smith' } + * splitName('Alice') // { firstName: 'Alice', lastName: '' } + * splitName('John Doe') // { firstName: 'John', lastName: 'Doe' } + * splitName('') // { firstName: '', lastName: '' } + */ +export const splitName = (fullName: string): { firstName: string; lastName: string } => { + const trimmedName = fullName.trim(); + if (!trimmedName) { + return { + firstName: '', + lastName: '' + }; + } + + // Split the name by spaces + const nameParts = trimmedName.split(/\s+/); + + // If only one word, treat it as firstName + if (nameParts.length === 1) { + return { + firstName: nameParts[0], + lastName: '' + }; + } + + // Last element is lastName, everything else is firstName + const lastName = nameParts.pop() || ''; + const firstName = nameParts.join(' '); + + return { firstName, lastName +}; +} diff --git a/test/helpers.test.ts b/test/helpers.test.ts index ea14b88..98f9259 100644 --- a/test/helpers.test.ts +++ b/test/helpers.test.ts @@ -1,4 +1,4 @@ -import { convertSecondsToTimeUnit, fileNameWithEllipsis } from '../src/helpers'; +import { convertSecondsToTimeUnit, fileNameWithEllipsis, splitName } from '../src/helpers'; describe('#convertSecondsToTimeUnit', () => { it("it should return { time: 1, unit: 'm' } if 60 seconds passed", () => { @@ -93,4 +93,35 @@ describe('fileNameWithEllipsis', () => { const file = { name: 'a.txt' }; expect(fileNameWithEllipsis(file)).toBe('a.txt'); }); + +}); + +describe('splitName', () => { + it('splits a basic first and last name', () => { + expect(splitName('John Doe')).toEqual({ + firstName: 'John', + lastName: 'Doe' + }); + }); + + it('handles single name', () => { + expect(splitName('John')).toEqual({ + firstName: 'John', + lastName: '' + }); + }); + + it('handles empty string', () => { + expect(splitName('Mary John Ann')).toEqual({ + firstName: 'Mary John', + lastName: 'Ann' + }); + }); + + it('handles extra whitespace', () => { + expect(splitName(' Jane Doe ')).toEqual({ + firstName: 'Jane', + lastName: 'Doe' + }); + }); }); diff --git a/yarn.lock b/yarn.lock index 10a8827..20bd0f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -992,6 +992,13 @@ "@jest/types" "^25.5.0" jest-mock "^25.5.0" +"@jest/expect-utils@^29.7.0": + version "29.7.0" + resolved "https://registry.yarnpkg.com/@jest/expect-utils/-/expect-utils-29.7.0.tgz#023efe5d26a8a70f21677d0a1afc0f0a44e3a1c6" + integrity sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA== + dependencies: + jest-get-type "^29.6.3" + "@jest/fake-timers@^25.5.0": version "25.5.0" resolved "https://registry.yarnpkg.com/@jest/fake-timers/-/fake-timers-25.5.0.tgz#46352e00533c024c90c2bc2ad9f2959f7f114185" @@ -1044,6 +1051,13 @@ optionalDependencies: node-notifier "^6.0.0" +"@jest/schemas@^29.6.3": + version "29.6.3" + resolved "https://registry.yarnpkg.com/@jest/schemas/-/schemas-29.6.3.tgz#430b5ce8a4e0044a7e3819663305a7b3091c8e03" + integrity sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA== + dependencies: + "@sinclair/typebox" "^0.27.8" + "@jest/source-map@^25.5.0": version "25.5.0" resolved "https://registry.yarnpkg.com/@jest/source-map/-/source-map-25.5.0.tgz#df5c20d6050aa292c2c6d3f0d2c7606af315bd1b" @@ -1106,6 +1120,18 @@ "@types/yargs" "^15.0.0" chalk "^3.0.0" +"@jest/types@^29.6.3": + version "29.6.3" + resolved "https://registry.yarnpkg.com/@jest/types/-/types-29.6.3.tgz#1131f8cf634e7e84c5e77bab12f052af585fba59" + integrity sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw== + dependencies: + "@jest/schemas" "^29.6.3" + "@types/istanbul-lib-coverage" "^2.0.0" + "@types/istanbul-reports" "^3.0.0" + "@types/node" "*" + "@types/yargs" "^17.0.8" + chalk "^4.0.0" + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -1184,6 +1210,11 @@ estree-walker "^1.0.1" picomatch "^2.2.2" +"@sinclair/typebox@^0.27.8": + version "0.27.8" + resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" + integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA== + "@sinonjs/commons@^1.7.0": version "1.8.3" resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.3.tgz#3802ddd21a50a949b6721ddd72da36e67e7f1b2d" @@ -1289,6 +1320,13 @@ "@types/istanbul-lib-coverage" "*" "@types/istanbul-lib-report" "*" +"@types/istanbul-reports@^3.0.0": + version "3.0.4" + resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-3.0.4.tgz#0f03e3d2f670fbdac586e34b433783070cc16f54" + integrity sha512-pk2B1NWalF9toCRu6gjBzR69syFjP4Od8WRAX+0mmf9lAjCRicLOWc+ZrxZHx/0XRjotgkF9t6iaMJ+aXcOdZQ== + dependencies: + "@types/istanbul-lib-report" "*" + "@types/jest@^25.2.1": version "25.2.3" resolved "https://registry.yarnpkg.com/@types/jest/-/jest-25.2.3.tgz#33d27e4c4716caae4eced355097a47ad363fdcaf" @@ -1297,6 +1335,14 @@ jest-diff "^25.2.1" pretty-format "^25.2.1" +"@types/jest@^29.5.14": + version "29.5.14" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.14.tgz#2b910912fa1d6856cadcd0c1f95af7df1d6049e5" + integrity sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ== + dependencies: + expect "^29.0.0" + pretty-format "^29.0.0" + "@types/json-schema@^7.0.3": version "7.0.7" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad" @@ -1339,6 +1385,11 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw== +"@types/stack-utils@^2.0.0": + version "2.0.3" + resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8" + integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw== + "@types/yargs-parser@*": version "20.2.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.0.tgz#dd3e6699ba3237f0348cd085e4698780204842f9" @@ -1351,6 +1402,13 @@ dependencies: "@types/yargs-parser" "*" +"@types/yargs@^17.0.8": + version "17.0.33" + resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.33.tgz#8c32303da83eec050a84b3c7ae7b9f922d13e32d" + integrity sha512-WpxBCKWPLr4xSsHgz511rFJAM+wS28w2zEO1QDNY5zM/S8ok70NNfztH0xwhqKyaK0OHCbN98LDAZuy1ctxDkA== + dependencies: + "@types/yargs-parser" "*" + "@typescript-eslint/eslint-plugin@^2.12.0": version "2.34.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.34.0.tgz#6f8ce8a46c7dea4a6f1d171d2bb8fbae6dac2be9" @@ -1483,6 +1541,11 @@ ansi-styles@^4.0.0, ansi-styles@^4.1.0: dependencies: color-convert "^2.0.1" +ansi-styles@^5.0.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-5.2.0.tgz#07449690ad45777d1924ac2abb2fc8895dba836b" + integrity sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA== + anymatch@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb" @@ -2007,6 +2070,11 @@ ci-info@^2.0.0: resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== +ci-info@^3.2.0: + version "3.9.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.9.0.tgz#4279a62028a7b1f262f3473fc9605f5e218c59b4" + integrity sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ== + class-utils@^0.3.5: version "0.3.6" resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463" @@ -2335,6 +2403,11 @@ diff-sequences@^25.2.6: resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-25.2.6.tgz#5f467c00edd35352b7bca46d7927d60e687a76dd" integrity sha512-Hq8o7+6GaZeoFjtpgvRBUknSXNeJiCx7V9Fr94ZMljNiCr9n9L8H8aJqgWOQiDDGdyn29fRNcDdRVJ5fdyihfg== +diff-sequences@^29.6.3: + version "29.6.3" + resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-29.6.3.tgz#4deaf894d11407c51efc8418012f9e70b84ea921" + integrity sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q== + dir-glob@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" @@ -2904,6 +2977,17 @@ expect@^25.5.0: jest-message-util "^25.5.0" jest-regex-util "^25.2.6" +expect@^29.0.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/expect/-/expect-29.7.0.tgz#578874590dcb3214514084c08115d8aee61e11bc" + integrity sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw== + dependencies: + "@jest/expect-utils" "^29.7.0" + jest-get-type "^29.6.3" + jest-matcher-utils "^29.7.0" + jest-message-util "^29.7.0" + jest-util "^29.7.0" + extend-shallow@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f" @@ -3249,6 +3333,11 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.6.tgz#ff040b2b0853b23c3d31027523706f1885d76bee" integrity sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ== +graceful-fs@^4.2.9: + version "4.2.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" + integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== + growly@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" @@ -3830,6 +3919,16 @@ jest-diff@^25.2.1, jest-diff@^25.5.0: jest-get-type "^25.2.6" pretty-format "^25.5.0" +jest-diff@^29.7.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-29.7.0.tgz#017934a66ebb7ecf6f205e84699be10afd70458a" + integrity sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw== + dependencies: + chalk "^4.0.0" + diff-sequences "^29.6.3" + jest-get-type "^29.6.3" + pretty-format "^29.7.0" + jest-docblock@^25.3.0: version "25.3.0" resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-25.3.0.tgz#8b777a27e3477cd77a168c05290c471a575623ef" @@ -3877,6 +3976,11 @@ jest-get-type@^25.2.6: resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-25.2.6.tgz#0b0a32fab8908b44d508be81681487dbabb8d877" integrity sha512-DxjtyzOHjObRM+sM1knti6or+eOgcGU4xVSb2HNP1TqO4ahsT+rqZg+nyqHWJSvWgKC5cG3QjGFBqxLghiF/Ig== +jest-get-type@^29.6.3: + version "29.6.3" + resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-29.6.3.tgz#36f499fdcea197c1045a127319c0481723908fd1" + integrity sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw== + jest-haste-map@^25.5.1: version "25.5.1" resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-25.5.1.tgz#1df10f716c1d94e60a1ebf7798c9fb3da2620943" @@ -3938,6 +4042,16 @@ jest-matcher-utils@^25.5.0: jest-get-type "^25.2.6" pretty-format "^25.5.0" +jest-matcher-utils@^29.7.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz#ae8fec79ff249fd592ce80e3ee474e83a6c44f12" + integrity sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g== + dependencies: + chalk "^4.0.0" + jest-diff "^29.7.0" + jest-get-type "^29.6.3" + pretty-format "^29.7.0" + jest-message-util@^25.5.0: version "25.5.0" resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-25.5.0.tgz#ea11d93204cc7ae97456e1d8716251185b8880ea" @@ -3952,6 +4066,21 @@ jest-message-util@^25.5.0: slash "^3.0.0" stack-utils "^1.0.1" +jest-message-util@^29.7.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-29.7.0.tgz#8bc392e204e95dfe7564abbe72a404e28e51f7f3" + integrity sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w== + dependencies: + "@babel/code-frame" "^7.12.13" + "@jest/types" "^29.6.3" + "@types/stack-utils" "^2.0.0" + chalk "^4.0.0" + graceful-fs "^4.2.9" + micromatch "^4.0.4" + pretty-format "^29.7.0" + slash "^3.0.0" + stack-utils "^2.0.3" + jest-mock@^25.5.0: version "25.5.0" resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-25.5.0.tgz#a91a54dabd14e37ecd61665d6b6e06360a55387a" @@ -4089,6 +4218,18 @@ jest-util@^25.5.0: is-ci "^2.0.0" make-dir "^3.0.0" +jest-util@^29.7.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.7.0.tgz#23c2b62bfb22be82b44de98055802ff3710fc0bc" + integrity sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA== + dependencies: + "@jest/types" "^29.6.3" + "@types/node" "*" + chalk "^4.0.0" + ci-info "^3.2.0" + graceful-fs "^4.2.9" + picomatch "^2.2.3" + jest-validate@^25.5.0: version "25.5.0" resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-25.5.0.tgz#fb4c93f332c2e4cf70151a628e58a35e459a413a" @@ -5106,6 +5247,15 @@ pretty-format@^25.2.1, pretty-format@^25.5.0: ansi-styles "^4.0.0" react-is "^16.12.0" +pretty-format@^29.0.0, pretty-format@^29.7.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.7.0.tgz#ca42c758310f365bfa71a0bda0a807160b776812" + integrity sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ== + dependencies: + "@jest/schemas" "^29.6.3" + ansi-styles "^5.0.0" + react-is "^18.0.0" + progress-estimator@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/progress-estimator/-/progress-estimator-0.2.2.tgz#1c3947a5782ea56e40c8fccc290ac7ceeb1b91cb" @@ -5178,6 +5328,11 @@ react-is@^16.12.0, react-is@^16.8.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== +react-is@^18.0.0: + version "18.3.1" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e" + integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg== + read-pkg-up@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-3.0.0.tgz#3ed496685dba0f8fe118d0691dc51f4a1ff96f07" @@ -5863,6 +6018,13 @@ stack-utils@^1.0.1: dependencies: escape-string-regexp "^2.0.0" +stack-utils@^2.0.3: + version "2.0.6" + resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-2.0.6.tgz#aaf0748169c02fc33c8232abccf933f54a1cc34f" + integrity sha512-XlkWvfIm6RmsWtNJx+uqtKLS8eqFbxUg0ZzLXqY0caEy9l7hruX8IpiDnjsLavoBgqCCR71TqWO8MaXYheJ3RQ== + dependencies: + escape-string-regexp "^2.0.0" + static-extend@^0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" From 70b947a240c33b12de561778d11999b532b6399e Mon Sep 17 00:00:00 2001 From: Pranav Date: Wed, 27 Nov 2024 16:58:10 -0800 Subject: [PATCH 2/5] v0.0.29 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 58df1e5..6bce9fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chatwoot/utils", - "version": "0.0.28", + "version": "0.0.29", "description": "Chatwoot utils", "private": false, "license": "MIT", From 1ac9e23572514b8fa463a75fc433c41e6f93cd38 Mon Sep 17 00:00:00 2001 From: Pranav Date: Wed, 27 Nov 2024 17:01:05 -0800 Subject: [PATCH 3/5] Update eslint --- src/helpers.ts | 11 ++++++----- test/helpers.test.ts | 15 +++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index d676ded..b5be36b 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -162,12 +162,14 @@ export const fileNameWithEllipsis = ( * splitName('John Doe') // { firstName: 'John', lastName: 'Doe' } * splitName('') // { firstName: '', lastName: '' } */ -export const splitName = (fullName: string): { firstName: string; lastName: string } => { +export const splitName = ( + fullName: string +): { firstName: string; lastName: string } => { const trimmedName = fullName.trim(); if (!trimmedName) { return { firstName: '', - lastName: '' + lastName: '', }; } @@ -178,7 +180,7 @@ export const splitName = (fullName: string): { firstName: string; lastName: stri if (nameParts.length === 1) { return { firstName: nameParts[0], - lastName: '' + lastName: '', }; } @@ -186,6 +188,5 @@ export const splitName = (fullName: string): { firstName: string; lastName: stri const lastName = nameParts.pop() || ''; const firstName = nameParts.join(' '); - return { firstName, lastName + return { firstName, lastName }; }; -} diff --git a/test/helpers.test.ts b/test/helpers.test.ts index 98f9259..9958b13 100644 --- a/test/helpers.test.ts +++ b/test/helpers.test.ts @@ -1,4 +1,8 @@ -import { convertSecondsToTimeUnit, fileNameWithEllipsis, splitName } from '../src/helpers'; +import { + convertSecondsToTimeUnit, + fileNameWithEllipsis, + splitName, +} from '../src/helpers'; describe('#convertSecondsToTimeUnit', () => { it("it should return { time: 1, unit: 'm' } if 60 seconds passed", () => { @@ -93,35 +97,34 @@ describe('fileNameWithEllipsis', () => { const file = { name: 'a.txt' }; expect(fileNameWithEllipsis(file)).toBe('a.txt'); }); - }); describe('splitName', () => { it('splits a basic first and last name', () => { expect(splitName('John Doe')).toEqual({ firstName: 'John', - lastName: 'Doe' + lastName: 'Doe', }); }); it('handles single name', () => { expect(splitName('John')).toEqual({ firstName: 'John', - lastName: '' + lastName: '', }); }); it('handles empty string', () => { expect(splitName('Mary John Ann')).toEqual({ firstName: 'Mary John', - lastName: 'Ann' + lastName: 'Ann', }); }); it('handles extra whitespace', () => { expect(splitName(' Jane Doe ')).toEqual({ firstName: 'Jane', - lastName: 'Doe' + lastName: 'Doe', }); }); }); From 6bcf49b5bcae62ec136ebea355cf39f009198fa7 Mon Sep 17 00:00:00 2001 From: Pranav Date: Wed, 27 Nov 2024 17:08:10 -0800 Subject: [PATCH 4/5] Update export --- src/index.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6f6a336..97a1857 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import { trimContent, convertSecondsToTimeUnit, fileNameWithEllipsis, + splitName, } from './helpers'; import { parseBoolean } from './string'; @@ -21,21 +22,22 @@ import { createTypingIndicator } from './typingStatus'; import { evaluateSLAStatus } from './sla'; export { + clamp, + convertSecondsToTimeUnit, + createTypingIndicator, debounce, - formatTime, + evaluateSLAStatus, + fileNameWithEllipsis, formatDate, + formatTime, getContrastingTextColor, - trimContent, + getMessageVariables, + getQuantileIntervals, + getUndefinedVariablesInMessage, parseBoolean, - sortAsc, quantile, - clamp, - getQuantileIntervals, - getMessageVariables, replaceVariablesInMessage, - getUndefinedVariablesInMessage, - createTypingIndicator, - convertSecondsToTimeUnit, - fileNameWithEllipsis, - evaluateSLAStatus, + sortAsc, + splitName, + trimContent, }; From be5653286403d6372752ee9b9149c7ec415f03f8 Mon Sep 17 00:00:00 2001 From: Pranav Date: Wed, 27 Nov 2024 17:08:37 -0800 Subject: [PATCH 5/5] v0.0.30 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6bce9fb..5d381b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chatwoot/utils", - "version": "0.0.29", + "version": "0.0.30", "description": "Chatwoot utils", "private": false, "license": "MIT",