How to shorten string length but keep ending with javascript?

i need you help again for a JavaScript, I’m not sure how to start.
If it’s a really stupid question, please just don’t answer.

Input examples:

123456_78910_KK_TK_MAAA_123_123456_DOC

123456_78911_KTT_TK_MAAA_123_654321_TXT

123456_10987_KK_TK_BEEE_123_12345678910111213_FILE

Output, string length = 30 + _DOC / _TXT / _FILE:

123456_78910_KK_TK_MAAA__DOC -> 123456_78910_KK_TK_MAAA_DOC

123456_78911_KTT_TK_MAAA__TXT -> 123456_78911_KTT_TK_MAAA_TXT

123456_10987_KK_TK_BEEE_FILE

Thanks a lot for you help.