@@ -15,6 +15,7 @@ import {
1515 toPathCase ,
1616 toSnakeCase ,
1717 toUpperCase ,
18+ transformArrayStrings ,
1819} from "../src" ;
1920
2021describe ( "toCamelCase" , ( ) => {
@@ -622,3 +623,155 @@ describe("convertWithCustomDelimiter", () => {
622623 expect ( result ) . toBe ( "testString" ) ;
623624 } ) ;
624625} ) ;
626+
627+ describe ( "transformArrayStrings - success cases" , ( ) => {
628+ test ( "camel case" , ( ) => {
629+ const input = [ "hello_world" , "this_is_a_test" ] ;
630+ expect ( transformArrayStrings ( input , "camel" ) ) . toEqual (
631+ input . map ( toCamelCase ) ,
632+ ) ;
633+ } ) ;
634+
635+ test ( "pascal case" , ( ) => {
636+ const input = [ "hello world" , "another example" ] ;
637+ expect ( transformArrayStrings ( input , "pascal" ) ) . toEqual (
638+ input . map ( toPascalCase ) ,
639+ ) ;
640+ } ) ;
641+
642+ test ( "kebab case" , ( ) => {
643+ const input = [ "Hello World" , "Another Test" ] ;
644+ expect ( transformArrayStrings ( input , "kebab" ) ) . toEqual (
645+ input . map ( toKebabCase ) ,
646+ ) ;
647+ } ) ;
648+
649+ test ( "UPPERCASE" , ( ) => {
650+ const input = [ "hello" , "world" ] ;
651+ expect ( transformArrayStrings ( input , "upper" ) ) . toEqual (
652+ input . map ( toUpperCase ) ,
653+ ) ;
654+ } ) ;
655+
656+ test ( "Capital Case" , ( ) => {
657+ const input = [ "hello world" , "nice day" ] ;
658+ expect ( transformArrayStrings ( input , "capital" ) ) . toEqual (
659+ input . map ( toCapitalCase ) ,
660+ ) ;
661+ } ) ;
662+
663+ test ( "CONSTANT_CASE" , ( ) => {
664+ const input = [ "my value" , "another one" ] ;
665+ expect ( transformArrayStrings ( input , "constant" ) ) . toEqual (
666+ input . map ( toConstantCase ) ,
667+ ) ;
668+ } ) ;
669+
670+ test ( "dot.case" , ( ) => {
671+ const input = [ "Dot Case Here" , "Another.Value" ] ;
672+ expect ( transformArrayStrings ( input , "dot" ) ) . toEqual ( input . map ( toDotCase ) ) ;
673+ } ) ;
674+
675+ test ( "no case" , ( ) => {
676+ const input = [ "No-Case-Here" , "Also.This" ] ;
677+ expect ( transformArrayStrings ( input , "no" ) ) . toEqual ( input . map ( toNoCase ) ) ;
678+ } ) ;
679+
680+ test ( "snake_case" , ( ) => {
681+ const input = [ "snake case" , "AnotherTest" ] ;
682+ expect ( transformArrayStrings ( input , "snake" ) ) . toEqual (
683+ input . map ( toSnakeCase ) ,
684+ ) ;
685+ } ) ;
686+
687+ test ( "path/case" , ( ) => {
688+ const input = [ "path case" , "Another Test" ] ;
689+ expect ( transformArrayStrings ( input , "path" ) ) . toEqual ( input . map ( toPathCase ) ) ;
690+ } ) ;
691+
692+ test ( "COBOL-CASE" , ( ) => {
693+ const input = [ "Cobol Case" , "Hard Core" ] ;
694+ expect ( transformArrayStrings ( input , "cobol" ) ) . toEqual (
695+ input . map ( toCobolCase ) ,
696+ ) ;
697+ } ) ;
698+
699+ test ( "leet speak" , ( ) => {
700+ const input = [ "leet" , "speak" ] ;
701+ expect ( transformArrayStrings ( input , "leet" ) ) . toEqual (
702+ input . map ( toLeetSpeak ) ,
703+ ) ;
704+ } ) ;
705+
706+ test ( "reverse" , ( ) => {
707+ const input = [ "abc" , "123" ] ;
708+ expect ( transformArrayStrings ( input , "reverse" ) ) . toEqual (
709+ input . map ( reverseString ) ,
710+ ) ;
711+ } ) ;
712+
713+ test ( "substring" , ( ) => {
714+ const input = [ "hello world" , "javascript" ] ;
715+ const options = { start : 0 , end : 4 } ;
716+ expect ( transformArrayStrings ( input , "substring" , options ) ) . toEqual (
717+ input . map ( ( str ) => substring ( str , options . start , options . end ) ) ,
718+ ) ;
719+ } ) ;
720+
721+ test ( "custom delimiter" , ( ) => {
722+ const input = [ "one_two" , "three_four" ] ;
723+ const options = { fromDelimiter : "_" , toDelimiter : "-" } ;
724+ expect ( transformArrayStrings ( input , "custom" , options ) ) . toEqual (
725+ input . map ( ( str ) => convertWithCustomDelimiter ( str , "_" , "-" ) ) ,
726+ ) ;
727+ } ) ;
728+
729+ test ( "empty array returns empty array" , ( ) => {
730+ expect ( transformArrayStrings ( [ ] , "camel" ) ) . toEqual ( [ ] ) ;
731+ } ) ;
732+
733+ test ( "works with empty strings" , ( ) => {
734+ const input = [ "" , "" ] ;
735+ expect ( transformArrayStrings ( input , "upper" ) ) . toEqual ( [ "" , "" ] ) ;
736+ } ) ;
737+ } ) ;
738+
739+ describe ( "transformArrayStrings - error handling" , ( ) => {
740+ test ( "throws on unsupported case type" , ( ) => {
741+ expect ( ( ) => transformArrayStrings ( [ "test" ] , "invalid" ) ) . toThrow (
742+ / U n s u p p o r t e d c a s e t y p e / ,
743+ ) ;
744+ } ) ;
745+
746+ test ( "throws if input is not an array" , ( ) => {
747+ expect ( ( ) => transformArrayStrings ( "not-an-array" , "camel" ) ) . toThrow (
748+ TypeError ,
749+ ) ;
750+ } ) ;
751+
752+ test ( "throws if array contains non-strings" , ( ) => {
753+ expect ( ( ) => transformArrayStrings ( [ "valid" , 123 ] , "camel" ) ) . toThrow (
754+ TypeError ,
755+ ) ;
756+ } ) ;
757+
758+ test ( "throws if substring is missing options" , ( ) => {
759+ expect ( ( ) => transformArrayStrings ( [ "hello" ] , "substring" ) ) . toThrow ( ) ;
760+ } ) ;
761+
762+ test ( "throws if custom delimiter is missing options" , ( ) => {
763+ expect ( ( ) => transformArrayStrings ( [ "x_y" ] , "custom" ) ) . toThrow ( ) ;
764+ } ) ;
765+
766+ test ( "throws if custom delimiter is missing fromDelimiter" , ( ) => {
767+ expect ( ( ) =>
768+ transformArrayStrings ( [ "x_y" ] , "custom" , { toDelimiter : "-" } ) ,
769+ ) . toThrow ( ) ;
770+ } ) ;
771+
772+ test ( "throws if custom delimiter is missing toDelimiter" , ( ) => {
773+ expect ( ( ) =>
774+ transformArrayStrings ( [ "x_y" ] , "custom" , { fromDelimiter : "_" } ) ,
775+ ) . toThrow ( ) ;
776+ } ) ;
777+ } ) ;
0 commit comments