segment-web.js 769 B

12345678910111213141516171819202122232425
  1. import { Segment, useDefault } from "segmentit";
  2. let segmentit;
  3. let hansIntlSegmenter;
  4. export function segment(hans, segment) {
  5. if (segment === "segmentit") {
  6. if (!segmentit) {
  7. segmentit = useDefault(new Segment());
  8. }
  9. return segmentit.doSegment(hans, {
  10. simple: true,
  11. });
  12. }
  13. if (segment === "Intl.Segmenter") {
  14. if (typeof Intl?.Segmenter === "function") {
  15. if (!hansIntlSegmenter) {
  16. hansIntlSegmenter = new Intl.Segmenter("zh-Hans-CN", {
  17. granularity: "word",
  18. });
  19. }
  20. return [...hansIntlSegmenter.segment(hans)].map((s) => s.segment);
  21. }
  22. }
  23. return [hans];
  24. }
  25. //# sourceMappingURL=segment-web.js.map