Digital pulse-shape discrimination (PSD) systems are widely used to extract various kinds of information from the shape of output pulses of radiation detectors. Such systems replace the traditional analog PSD circuits with numerical algorithms running on a digital processor which makes them more flexible for implementing various PSD methods. However, the available digital PSD algorithms have been generally tailored to the characteristics of the concerned detectors which limits their general use. Here, for the purpose of building a general-purpose digital PSD module, we present a PSD algorithm that with minimum alterations can be used with a wide range of radiation detectors. Our approach is based on using the cosine similarity measure to quantify the variations in the shape of detectors' pulses with respect to the shape of a unit step pulse. The method is described in details, and the results of the test experiments with different types of radiation detectors, including a boron tetrafluoride (BF3) proportional counter, a liquid scintillation detector, and a high purity germanium (HPGe) detector are shown. The performance of the algorithm is also compared to that of the common rise-time discrimination method.