It works like an improvised weapon, with improvised weapons stats and rules
From Sage advice by Jeremy Crawford
@Amos_Fawkes: @JeremyECrawford A Ranged Weapon (Bow) used to make a Melee Attack (Smack). Do you still add proficiency to the attack roll?
@JeremyECrawford: A weapon with the ammunition property works as an improvised weapon when you smack someone with it (PH, 146–7).
So it's treated entirely like an improvised weapon. The wording on that section is a bit ambiguous, I agree.
Since you asked about darts, yes, they would work like any other improvised weapon by RAW:
An improvised weapon includes any object you can wield in one or two hands...In many cases, an improvised weapon is similar to an actual weapon and can be treated as such.
That is, unless the DM rules that a certain thrown weapon works as a different weapon, as per this question. So maybe you could use a dart as an improvised dagger, and your DM may let you use your proficency bonus (if you have it) for the attack. In any case, the stats of the original weapon would not be used at all (though they may be pretty similar).
To clarify, you cannot make a melee attack with a ranged weapon:
Every weapon is classified as either melee or ranged. A melee weapon is used to Attack a target within 5 feet of you, whereas a ranged weapon is used to Attack a target at a distance.
But you can use a ranged weapon as an improvised melee weapon, and make a melee attack with that improvise melee weapon. Confusing, I know.