{"id":26926616,"url":"https://github.com/skyfi/font","last_synced_at":"2025-04-02T03:34:42.008Z","repository":{"id":57218863,"uuid":"104726336","full_name":"skyFi/font","owner":"skyFi","description":"与文字相关的库（大小位置控制等）","archived":false,"fork":false,"pushed_at":"2018-05-10T07:08:41.000Z","size":134,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T14:50:17.574Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skyFi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-25T08:56:40.000Z","updated_at":"2018-12-28T15:51:47.000Z","dependencies_parsed_at":"2022-08-29T02:11:48.755Z","dependency_job_id":null,"html_url":"https://github.com/skyFi/font","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyFi%2Ffont","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyFi%2Ffont/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyFi%2Ffont/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyFi%2Ffont/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skyFi","download_url":"https://codeload.github.com/skyFi/font/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246752339,"owners_count":20827982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-02T03:34:41.946Z","updated_at":"2025-04-02T03:34:42.001Z","avatar_url":"https://github.com/skyFi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# font\n\n需求列表：\n\n- [x] 智能多行省略，JavaScript截断文字（尾部空格，自定义省略符号等）beta\n- [x] 计算文字的宽度（给一串文字，告诉你它的宽度）\n\n# Install\n\n```\nnpm install easyfont --save\n```\n\n# Usage\n\n```\nimport EasyFont from 'easyfont';\n\n// 例子采用ES7语法，需你自行替换到当前工程语言环境，建议使用ES7，为啥？看着舒服，读起来简单明了 ^o^\n// 截断字符\nconst omit = async (str) =\u003e {\n  const result = await new EasyFont().pipe(str)\n          .operation('truncate')\n          .option({ width: 270, row: 2, fontSize: 14, fontFamily: \"'PingFang SC', sans-serif\" })\n          .value();\n  return result;\n}\n\n// 获取文字宽度\nconst measure = async (str) =\u003e {\n  const result = await new EasyFont().pipe(str)\n          .operation('measure')\n          .option({ fontSize: 14, fontFamily: \"'PingFang SC', sans-serif\" })\n          .value();\n  return result;\n}\n...\nconst res1 = await omit('Skylor.min is very handsome!');\nconst res2 = await measure('Skylor.min is very handsome!');\nconsole.log(res1.result); // 省略后的字符，或许这就是你需要的 ^o^\nconsole.log(res2.width); // 测量文字的宽度\n...\n```\n\n# Option\n\n* fontSize -\u003e set font size.\n* fontFamily -\u003e set font family, eg: 'PingFang SC', sans-serif.\n* fontWeight -\u003e set font weight, eg: bold.\n* src -\u003e set font src, (use for custom font family, deprecated!)\n* width -\u003e set font box width.\n* row -\u003e omit the number of rows.\n* lack -\u003e at the end of the space num.\n* ellipsis -\u003e custom apostrophes.\n\n# Method\n\n_this = new EasyFont();_\n\n## pipi(string)\n导入需要操作的字符串到操作流中。\n* 参数\n\n  1. string __(String)__ 导入的字符串\n* 返回\n  * 流\n\n## id(any)\n标记返回结果，在特定情况这个可能会拯救你的人生\n* 参数\n\n  1. any __(Any)__ 标记的记号，可以是任何你想放进去的格式\n* 返回\n  * 流\n\n## operation(type)\n\n操作类型，暂时可以为`measure`和`truncate`这两个值\n\n* 参数\n\n  1. type __(Type)__ 操作类型\n\n     * `measure`：测量字符串，最后返回宽度等信息\n\n\n     * `truncate`：截断字符串，最后返回截断后的字符串等信息\n\n* 返回\n\n  * 流\n\n## option(option)\n\n字符串操作的配置信息\n\n* 参数\n  * option __(Object)__ 配置，具体见上面的配置\n* 返回\n  * 流\n\n## value()\n\n流操作的终止函数，也是获取最后值的函数\n\n* 返回\n  * Promise 返回一个promise，值为操作的结果值。\n\n# License\n\nMIT License\n\nCopyright (c) 2017 fang.yongle\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyfi%2Ffont","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskyfi%2Ffont","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyfi%2Ffont/lists"}