Clean up the oopsie. Rebuild the blank exercises.

This commit is contained in:
Michael Frank
2021-05-09 00:39:21 +12:00
parent b984cb4c6f
commit d28d80c46f
1565 changed files with 27186 additions and 199003 deletions
+16 -5
View File
@@ -1,18 +1,25 @@
'use strict';
const stripAnsi = require('strip-ansi');
const isFullwidthCodePoint = require('is-fullwidth-code-point');
const emojiRegex = require('emoji-regex');
module.exports = str => {
if (typeof str !== 'string' || str.length === 0) {
const stringWidth = string => {
if (typeof string !== 'string' || string.length === 0) {
return 0;
}
str = stripAnsi(str);
string = stripAnsi(string);
if (string.length === 0) {
return 0;
}
string = string.replace(emojiRegex(), ' ');
let width = 0;
for (let i = 0; i < str.length; i++) {
const code = str.codePointAt(i);
for (let i = 0; i < string.length; i++) {
const code = string.codePointAt(i);
// Ignore control characters
if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
@@ -34,3 +41,7 @@ module.exports = str => {
return width;
};
module.exports = stringWidth;
// TODO: remove this in the next major version
module.exports.default = stringWidth;
+24 -22
View File
@@ -1,28 +1,29 @@
{
"_from": "string-width@^2.1.0",
"_id": "string-width@2.1.1",
"_from": "string-width@^4.2.0",
"_id": "string-width@4.2.2",
"_inBundle": false,
"_integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
"_integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
"_location": "/string-width",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "string-width@^2.1.0",
"raw": "string-width@^4.2.0",
"name": "string-width",
"escapedName": "string-width",
"rawSpec": "^2.1.0",
"rawSpec": "^4.2.0",
"saveSpec": null,
"fetchSpec": "^2.1.0"
"fetchSpec": "^4.2.0"
},
"_requiredBy": [
"/inquirer",
"/table"
"/cliui",
"/wrap-ansi",
"/yargs"
],
"_resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
"_shasum": "ab93f27a8dc13d28cac815c462143a6d9012ae9e",
"_spec": "string-width@^2.1.0",
"_where": "/Users/cloyd/coderrr/odin/javascript-exercises/node_modules/inquirer",
"_resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz",
"_shasum": "dafd4f9559a7585cfba529c6a0a4f73488ebd4c5",
"_spec": "string-width@^4.2.0",
"_where": "/home/michael/projects/javascript-exercises/node_modules/yargs",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
@@ -33,27 +34,28 @@
},
"bundleDependencies": false,
"dependencies": {
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^4.0.0"
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.0"
},
"deprecated": false,
"description": "Get the visual width of a string - the number of columns required to display it",
"devDependencies": {
"ava": "*",
"xo": "*"
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
},
"engines": {
"node": ">=4"
"node": ">=8"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"homepage": "https://github.com/sindresorhus/string-width#readme",
"keywords": [
"string",
"str",
"character",
"char",
"unicode",
"width",
"visual",
@@ -82,7 +84,7 @@
"url": "git+https://github.com/sindresorhus/string-width.git"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"version": "2.1.1"
"version": "4.2.2"
}
+15 -7
View File
@@ -1,4 +1,4 @@
# string-width [![Build Status](https://travis-ci.org/sindresorhus/string-width.svg?branch=master)](https://travis-ci.org/sindresorhus/string-width)
# string-width
> Get the visual width of a string - the number of columns required to display it
@@ -19,14 +19,14 @@ $ npm install string-width
```js
const stringWidth = require('string-width');
stringWidth('a');
//=> 1
stringWidth('古');
//=> 2
stringWidth('\u001b[1m古\u001b[22m');
stringWidth('\u001B[1m古\u001B[22m');
//=> 2
stringWidth('a');
//=> 1
```
@@ -37,6 +37,14 @@ stringWidth('a');
- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
## License
---
MIT © [Sindre Sorhus](https://sindresorhus.com)
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-string-width?utm_source=npm-string-width&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>