-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cz-git): reduce word-wrap and temp dev number
link #2
- Loading branch information
Showing
10 changed files
with
260 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @description: fork by "word-wrap" v1.2.3" | ||
*/ | ||
|
||
function identity(str: string) { | ||
return str; | ||
} | ||
|
||
interface Options { | ||
width?: number; | ||
indent?: string; | ||
newline?: string; | ||
escape?: (str: string) => string; | ||
trim?: boolean; | ||
cut?: boolean; | ||
} | ||
|
||
export const wrap = (str: string, options: Options) => { | ||
options = options || {}; | ||
if (str == null) { | ||
return str; | ||
} | ||
|
||
const width = options.width || 50; | ||
const indent = typeof options.indent === "string" ? options.indent : ""; | ||
|
||
const newline = options.newline || "\n" + indent; | ||
const escape = typeof options.escape === "function" ? options.escape : identity; | ||
|
||
let regexString = ".{1," + width + "}"; | ||
if (options.cut !== true) { | ||
regexString += "([\\s\u200B]+|$)|[^\\s\u200B]+?([\\s\u200B]+|$)"; | ||
} | ||
|
||
const re = new RegExp(regexString, "g"); | ||
const lines = str.match(re) || []; | ||
let result = | ||
indent + | ||
lines | ||
.map(function (line) { | ||
if (line.slice(-1) === "\n") { | ||
line = line.slice(0, line.length - 1); | ||
} | ||
return escape(line); | ||
}) | ||
.join(newline); | ||
|
||
if (options.trim === true) { | ||
result = result.replace(/[ \t]*$/gm, ""); | ||
} | ||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.