@cjser/humanize-string 3.1.0-cjser.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // packages/@cjser/humanize-string.tmp-26-1778152025452/index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ default: () => humanizeString
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+ var import_decamelize = __toESM(require("@cjser/decamelize"), 1);
36
+ function humanizeString(string, options = {}) {
37
+ if (typeof string !== "string") {
38
+ throw new TypeError("Expected a string");
39
+ }
40
+ if (!options.preserveCase) {
41
+ string = (0, import_decamelize.default)(string);
42
+ string = string.toLowerCase();
43
+ }
44
+ string = string.replace(/[_-]+/g, " ").replace(/\s{2,}/g, " ").trim();
45
+ string = string.charAt(0).toUpperCase() + string.slice(1);
46
+ return string;
47
+ }
package/index.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ export type Options = {
2
+ /**
3
+ Preserve the original case instead of lowercasing.
4
+
5
+ @default false
6
+
7
+ @example
8
+ ```
9
+ import humanizeString from '@cjser/humanize-string';
10
+
11
+ humanizeString('The-NetApp-Guide-to-Kubernetes');
12
+ //=> 'The net app guide to kubernetes'
13
+
14
+ humanizeString('The-NetApp-Guide-to-Kubernetes', {preserveCase: true});
15
+ //=> 'The NetApp Guide to Kubernetes'
16
+ ```
17
+ */
18
+ readonly preserveCase?: boolean;
19
+ };
20
+
21
+ /**
22
+ Convert a camelized/dasherized/underscored string into a humanized one: `fooBar-Baz_Faz` → `Foo bar baz faz`.
23
+
24
+ @param text - The string to make human readable.
25
+
26
+ @example
27
+ ```
28
+ import humanizeString from '@cjser/humanize-string';
29
+
30
+ humanizeString('fooBar');
31
+ //=> 'Foo bar'
32
+
33
+ humanizeString('foo-bar');
34
+ //=> 'Foo bar'
35
+
36
+ humanizeString('foo_bar');
37
+ //=> 'Foo bar'
38
+ ```
39
+ */
40
+ export default function humanizeString(text: string, options?: Options): string;
package/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import decamelize from '@cjser/decamelize';
2
+
3
+ export default function humanizeString(string, options = {}) {
4
+ if (typeof string !== 'string') {
5
+ throw new TypeError('Expected a string');
6
+ }
7
+
8
+ if (!options.preserveCase) {
9
+ string = decamelize(string);
10
+ string = string.toLowerCase();
11
+ }
12
+
13
+ string = string.replace(/[_-]+/g, ' ').replace(/\s{2,}/g, ' ').trim();
14
+ string = string.charAt(0).toUpperCase() + string.slice(1);
15
+
16
+ return string;
17
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@cjser/humanize-string",
3
+ "version": "3.1.0-cjser.2",
4
+ "description": "Convert a camelized/dasherized/underscored string into a humanized one: `fooBar-Baz_Faz` → `Foo bar baz faz`",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/sponsors/sindresorhus",
11
+ "author": {
12
+ "name": "Sindre Sorhus",
13
+ "email": "sindresorhus@gmail.com",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "require": "./dist-cjser/index.cjs",
19
+ "default": "./index.js"
20
+ },
21
+ "types": "./index.d.ts",
22
+ "sideEffects": false,
23
+ "engines": {
24
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
25
+ },
26
+ "scripts": {
27
+ "test": "xo && ava && tsd"
28
+ },
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "dist-cjser"
33
+ ],
34
+ "keywords": [
35
+ "humanize",
36
+ "human",
37
+ "pretty",
38
+ "capitalize",
39
+ "uppercase",
40
+ "case",
41
+ "camelcase",
42
+ "dash",
43
+ "hyphen",
44
+ "underscore",
45
+ "string",
46
+ "text",
47
+ "convert"
48
+ ],
49
+ "dependencies": {
50
+ "@cjser/decamelize": "6.0.1-cjser.2"
51
+ },
52
+ "devDependencies": {
53
+ "ava": "^3.15.0",
54
+ "tsd": "^0.18.0",
55
+ "xo": "^0.45.0"
56
+ },
57
+ "main": "./dist-cjser/index.cjs",
58
+ "cjser": {
59
+ "sourceVersion": "3.1.0",
60
+ "cjserVersion": 2,
61
+ "original": {
62
+ "name": "humanize-string",
63
+ "version": "3.1.0",
64
+ "exports": "./index.js",
65
+ "repository": "sindresorhus/humanize-string",
66
+ "dependencies": {
67
+ "decamelize": "^6.0.0"
68
+ },
69
+ "files": [
70
+ "index.js",
71
+ "index.d.ts"
72
+ ],
73
+ "scripts": {
74
+ "test": "xo && ava && tsd"
75
+ }
76
+ }
77
+ }
78
+ }
package/readme.md ADDED
@@ -0,0 +1,65 @@
1
+ # humanize-string
2
+
3
+ > Convert a camelized/dasherized/underscored string into a humanized one
4
+ > Example: `fooBar-Baz_Faz` → `Foo bar baz faz`
5
+
6
+ ## Install
7
+
8
+ ```sh
9
+ npm install humanize-string
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```js
15
+ import humanizeString from 'humanize-string';
16
+
17
+ humanizeString('fooBar');
18
+ //=> 'Foo bar'
19
+
20
+ humanizeString('foo-bar');
21
+ //=> 'Foo bar'
22
+
23
+ humanizeString('foo_bar');
24
+ //=> 'Foo bar'
25
+ ```
26
+
27
+ ## API
28
+
29
+ ### humanizeString(input, options?)
30
+
31
+ #### input
32
+
33
+ Type: `string`
34
+
35
+ The string to humanize.
36
+
37
+ #### options
38
+
39
+ Type: `object`
40
+
41
+ ##### preserveCase
42
+
43
+ Type: `boolean`\
44
+ Default: `false`
45
+
46
+ Preserve the original case instead of lowercasing.
47
+
48
+ ```js
49
+ import humanizeString from 'humanize-string';
50
+
51
+ humanizeString('The-NetApp-Guide-to-Kubernetes');
52
+ //=> 'The net app guide to kubernetes'
53
+
54
+ humanizeString('The-NetApp-Guide-to-Kubernetes', {preserveCase: true});
55
+ //=> 'The NetApp Guide to Kubernetes'
56
+ ```
57
+
58
+ ## Related
59
+
60
+ - [camelcase](https://github.com/sindresorhus/camelcase) - Convert a dash/dot/underscore/space separated string to camelcase
61
+
62
+ ## cjser
63
+
64
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
65
+ Original repository: https://github.com/sindresorhus/humanize-string