UNPKG

korean-gotong

Version:

한글이 인생에 고통을 선사할 때마다 기능이 추가될 예정입니다.

104 lines (81 loc) 4.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UTF8Block = void 0; var _utils = require("../utils"); function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /** * UTF8 블록 정보를 저장하는 클래스 */ var UTF8Block = /*#__PURE__*/function () { function UTF8Block() { var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; _classCallCheck(this, UTF8Block); _defineProperty(this, "range", []); this.range = [{ start: start, end: end }]; } _createClass(UTF8Block, [{ key: "has", value: /** * 블록에 글자가 포함되는지 확인 * @param charCode 글자 코드 (`str.charCodeAt(0)`) * @returns 블록에 글자가 포함되는지 여부 */ function has(charCode) { return this.range.some(function (v) { return (0, _utils.within)(v.start, charCode, v.end); }); } /** * 여러 블록의 글자들을 모두 포함하는 새 블록 정보를 생성 * @param blocks 합칠 블록의 목록 * @returns 새 블록 인스턴스 */ }], [{ key: "join", value: function join() { var ret = new UTF8Block(); for (var _len = arguments.length, blocks = new Array(_len), _key = 0; _key < _len; _key++) { blocks[_key] = arguments[_key]; } var range = blocks.reduce(function (p, c) { return [].concat(_toConsumableArray(p), _toConsumableArray(c.range)); }, []).sort(function (a, b) { return a.start - b.start; }).reduce(function (previous, current) { if (previous.length > 0) { if ((0, _utils.within)(previous[0].start, current.start, previous[0].end)) { previous[0] = { start: previous[0].start, end: Math.max(previous[0].start, previous[0].end) }; return previous; } else { previous.unshift(current); return previous; } } return [current]; }, []).reverse(); ret.range = range; return ret; } }]); return UTF8Block; }(); exports.UTF8Block = UTF8Block;