segment-web.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var __read = (this && this.__read) || function (o, n) {
  2. var m = typeof Symbol === "function" && o[Symbol.iterator];
  3. if (!m) return o;
  4. var i = m.call(o), r, ar = [], e;
  5. try {
  6. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  7. }
  8. catch (error) { e = { error: error }; }
  9. finally {
  10. try {
  11. if (r && !r.done && (m = i["return"])) m.call(i);
  12. }
  13. finally { if (e) throw e.error; }
  14. }
  15. return ar;
  16. };
  17. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  18. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  19. if (ar || !(i in from)) {
  20. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  21. ar[i] = from[i];
  22. }
  23. }
  24. return to.concat(ar || Array.prototype.slice.call(from));
  25. };
  26. define(["require", "exports", "segmentit"], function (require, exports, segmentit_1) {
  27. "use strict";
  28. Object.defineProperty(exports, "__esModule", { value: true });
  29. exports.segment = void 0;
  30. var segmentit;
  31. var hansIntlSegmenter;
  32. function segment(hans, segment) {
  33. if (segment === "segmentit") {
  34. if (!segmentit) {
  35. segmentit = (0, segmentit_1.useDefault)(new segmentit_1.Segment());
  36. }
  37. return segmentit.doSegment(hans, {
  38. simple: true,
  39. });
  40. }
  41. if (segment === "Intl.Segmenter") {
  42. if (typeof (Intl === null || Intl === void 0 ? void 0 : Intl.Segmenter) === "function") {
  43. if (!hansIntlSegmenter) {
  44. hansIntlSegmenter = new Intl.Segmenter("zh-Hans-CN", {
  45. granularity: "word",
  46. });
  47. }
  48. return __spreadArray([], __read(hansIntlSegmenter.segment(hans)), false).map(function (s) { return s.segment; });
  49. }
  50. }
  51. return [hans];
  52. }
  53. exports.segment = segment;
  54. });
  55. //# sourceMappingURL=segment-web.js.map