TikTok is selling most of its U.S. operations to a group of American and Gulf investors in a bid to avert a nationwide ban over security concerns.