How do I safely interface an NPN or PNP sensor output with the GPIO pins on my Raspberry Pi?
NPN has an open-collector transistor between output and ground.  By itself, this transistor can only drive the line low.  To drive the line high, add a pull-up resistor to the +3.3V rail.  This can be interfaced directly to the GPIO input.

PNP has an open collector transistor between the output and the sensor's supply rail.  The minimum supply voltage is +10V.  You can't interface this PNP output directly to a Raspberry Pi.

Opto-isolator approach can work with either NPN or PNP output.

related:  

Manual for the color sensor in question.

Additional reading on PNP and NPN outputs: 
here
and here.  (Those are in the context of industrial controllers, rather than Raspberry Pi, though.)