@stacksjs/strings 0.53.1 → 0.56.23

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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
+ import pluralize from 'pluralize';
2
+ import * as detect_indent from 'detect-indent';
3
+ export { default as detectIndent } from 'detect-indent';
4
+ import { Macroable } from 'macroable';
5
+ export { detectNewline } from 'detect-newline';
1
6
  export { camelCase, capitalCase, constantCase, dotCase, headerCase, paramCase as kebabCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
2
7
  export { titleCase } from 'title-case';
3
- import pluralize from 'pluralize';
4
8
 
5
9
  interface SlugOptions {
6
10
  replacement?: string;
@@ -54,29 +58,31 @@ declare function ensureSuffix(suffix: string, str: string): string;
54
58
  * ```
55
59
  */
56
60
  declare function template(str: string, ...args: any[]): string;
61
+ declare function truncate(str: string, length: number, end?: string): string;
57
62
  /**
58
63
  * Generate a random string
59
64
  * @category String
60
65
  */
61
66
  declare function randomStr(size?: number, dict?: string): string;
62
67
  /**
63
- * First letter uppercase, other lowercase
68
+ * Slugify a string
64
69
  * @category string
65
70
  * @example
66
71
  * ```
67
- * capitalize('hello world') => 'Hello world'
72
+ * slug('Hello World') => 'hello-world'
68
73
  * ```
69
74
  */
70
- declare function capitalize(str: string): string;
75
+ declare function slug(str: string, options?: SlugOptions): string;
76
+
71
77
  /**
72
- * Slugify a string
78
+ * First letter uppercase, other lowercase
73
79
  * @category string
74
80
  * @example
75
81
  * ```
76
- * slug('Hello World') => 'hello-world'
82
+ * capitalize('hello world') => 'Hello world'
77
83
  * ```
78
84
  */
79
- declare function slug(str: string, options?: SlugOptions): string;
85
+ declare function capitalize(str: string): string;
80
86
 
81
87
  declare const plural: typeof pluralize.plural;
82
88
  declare const singular: typeof pluralize.singular;
@@ -87,4 +93,44 @@ declare const addSingularRule: typeof pluralize.addSingularRule;
87
93
  declare const addIrregularRule: typeof pluralize.addIrregularRule;
88
94
  declare const addUncountableRule: typeof pluralize.addUncountableRule;
89
95
 
90
- export { addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, capitalize, ensurePrefix, ensureSuffix, isPlural, isSingular, plural, randomStr, singular, slash, slug, template };
96
+ declare class Str extends Macroable {
97
+ slash(str: string): string;
98
+ ensurePrefix(prefix: string, str: string): string;
99
+ ensureSuffix(suffix: string, str: string): string;
100
+ template(str: string, ...args: any[]): string;
101
+ /**
102
+ * Truncate a string
103
+ */
104
+ truncate(str: string, length: number, end?: string): string;
105
+ random(length?: number): string;
106
+ capitalize(str: string): string;
107
+ slug(str: string): string;
108
+ detectIndent(str: string): detect_indent.Indent;
109
+ detectNewline(str: string): "\r\n" | "\n" | undefined;
110
+ camelCase(str: string): string;
111
+ capitalCase(str: string): string;
112
+ constantCase(str: string): string;
113
+ dotCase(str: string): string;
114
+ headerCase(str: string): string;
115
+ noCase(str: string): string;
116
+ paramCase(str: string): string;
117
+ pascalCase(str: string): string;
118
+ pathCase(str: string): string;
119
+ sentenceCase(str: string): string;
120
+ snakeCase(str: string): string;
121
+ titleCase(str: string): string;
122
+ kebabCase(str: string): string;
123
+ plural(str: string): string;
124
+ singular(str: string): string;
125
+ isPlural(str: string): boolean;
126
+ isSingular(str: string): boolean;
127
+ addPluralRule(rule: string | RegExp, repl: string): void;
128
+ addSingularRule(rule: string | RegExp, repl: string): void;
129
+ addIrregularRule(single: string, plural: string): void;
130
+ addUncountableRule(word: string | RegExp): void;
131
+ static macros: {};
132
+ static getters: {};
133
+ }
134
+ declare const str: Str;
135
+
136
+ export { Str, addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, capitalize, ensurePrefix, ensureSuffix, isPlural, isSingular, plural, randomStr, singular, slash, slug, str, template, truncate };
package/dist/index.mjs CHANGED
@@ -1,7 +1,14 @@
1
+ import slugify from 'slugify';
2
+ import detectIndent from 'detect-indent';
3
+ export { default as detectIndent } from 'detect-indent';
4
+ import { detectNewline } from 'detect-newline';
5
+ export { detectNewline } from 'detect-newline';
6
+ import { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
1
7
  export { camelCase, capitalCase, constantCase, dotCase, headerCase, paramCase as kebabCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
8
+ import { titleCase } from 'title-case';
2
9
  export { titleCase } from 'title-case';
3
- import slugify from 'slugify';
4
10
  import pluralize from 'pluralize';
11
+ import { Macroable } from 'macroable';
5
12
 
6
13
  const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
7
14
  function slash(str) {
@@ -25,6 +32,11 @@ function template(str, ...args) {
25
32
  return args[index];
26
33
  });
27
34
  }
35
+ function truncate(str, length, end = "...") {
36
+ if (str.length <= length)
37
+ return str;
38
+ return str.slice(0, length - end.length) + end;
39
+ }
28
40
  function randomStr(size = 16, dict = urlAlphabet) {
29
41
  let id = "";
30
42
  let i = size;
@@ -33,9 +45,6 @@ function randomStr(size = 16, dict = urlAlphabet) {
33
45
  id += dict[Math.random() * len | 0];
34
46
  return id;
35
47
  }
36
- function capitalize(str) {
37
- return str[0].toUpperCase() + str.slice(1).toLowerCase();
38
- }
39
48
  function slug(str, options) {
40
49
  if (options)
41
50
  return slugify(str, options);
@@ -45,6 +54,112 @@ function slug(str, options) {
45
54
  });
46
55
  }
47
56
 
57
+ function capitalize(str) {
58
+ return str[0].toUpperCase() + str.slice(1).toLowerCase();
59
+ }
60
+
48
61
  const { plural, singular, isPlural, isSingular, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule } = pluralize;
49
62
 
50
- export { addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, capitalize, ensurePrefix, ensureSuffix, isPlural, isSingular, plural, randomStr, singular, slash, slug, template };
63
+ class Str extends Macroable {
64
+ slash(str2) {
65
+ return slash(str2);
66
+ }
67
+ ensurePrefix(prefix, str2) {
68
+ return ensurePrefix(prefix, str2);
69
+ }
70
+ ensureSuffix(suffix, str2) {
71
+ return ensureSuffix(suffix, str2);
72
+ }
73
+ template(str2, ...args) {
74
+ return template(str2, ...args);
75
+ }
76
+ /**
77
+ * Truncate a string
78
+ */
79
+ truncate(str2, length, end = "...") {
80
+ return truncate(str2, length, end);
81
+ }
82
+ random(length = 16) {
83
+ return randomStr(length);
84
+ }
85
+ capitalize(str2) {
86
+ return capitalize(str2);
87
+ }
88
+ slug(str2) {
89
+ return slug(str2);
90
+ }
91
+ detectIndent(str2) {
92
+ return detectIndent(str2);
93
+ }
94
+ detectNewline(str2) {
95
+ return detectNewline(str2);
96
+ }
97
+ camelCase(str2) {
98
+ return camelCase(str2);
99
+ }
100
+ capitalCase(str2) {
101
+ return capitalCase(str2);
102
+ }
103
+ constantCase(str2) {
104
+ return constantCase(str2);
105
+ }
106
+ dotCase(str2) {
107
+ return dotCase(str2);
108
+ }
109
+ headerCase(str2) {
110
+ return headerCase(str2);
111
+ }
112
+ noCase(str2) {
113
+ return noCase(str2);
114
+ }
115
+ paramCase(str2) {
116
+ return paramCase(str2);
117
+ }
118
+ pascalCase(str2) {
119
+ return pascalCase(str2);
120
+ }
121
+ pathCase(str2) {
122
+ return pathCase(str2);
123
+ }
124
+ sentenceCase(str2) {
125
+ return sentenceCase(str2);
126
+ }
127
+ snakeCase(str2) {
128
+ return snakeCase(str2);
129
+ }
130
+ titleCase(str2) {
131
+ return titleCase(str2);
132
+ }
133
+ kebabCase(str2) {
134
+ return paramCase(str2);
135
+ }
136
+ plural(str2) {
137
+ return plural(str2);
138
+ }
139
+ singular(str2) {
140
+ return singular(str2);
141
+ }
142
+ isPlural(str2) {
143
+ return isPlural(str2);
144
+ }
145
+ isSingular(str2) {
146
+ return isSingular(str2);
147
+ }
148
+ addPluralRule(rule, repl) {
149
+ return addPluralRule(rule, repl);
150
+ }
151
+ addSingularRule(rule, repl) {
152
+ return addSingularRule(rule, repl);
153
+ }
154
+ addIrregularRule(single, plural) {
155
+ return addIrregularRule(single, plural);
156
+ }
157
+ addUncountableRule(word) {
158
+ return addUncountableRule(word);
159
+ }
160
+ }
161
+ Str.macros = {};
162
+ Str.getters = {};
163
+ const str = new Str();
164
+
165
+ export { Str, addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, capitalize, ensurePrefix, ensureSuffix, isPlural, isSingular, plural, randomStr, singular, slash, slug, str, template, truncate };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@stacksjs/strings",
3
3
  "type": "module",
4
- "version": "0.53.1",
5
- "packageManager": "pnpm@8.5.1",
4
+ "version": "0.56.23",
5
+ "packageManager": "pnpm@8.6.5",
6
6
  "description": "The Stacks string utilities.",
7
7
  "author": "Chris Breuer",
8
8
  "license": "MIT",
@@ -40,6 +40,7 @@
40
40
  "import": "./dist/index.mjs"
41
41
  }
42
42
  },
43
+ "main": "dist/index.mjs",
43
44
  "module": "dist/index.mjs",
44
45
  "types": "dist/index.d.ts",
45
46
  "contributors": [
@@ -53,15 +54,21 @@
53
54
  "@types/pluralize": "^0.0.29",
54
55
  "@types/validator": "^13.7.17",
55
56
  "change-case": "^4.1.2",
57
+ "detect-indent": "^7.0.1",
58
+ "detect-newline": "^4.0.0",
59
+ "macroable": "^7.0.2",
56
60
  "pluralize": "^8.0.0",
57
61
  "slugify": "^1.6.6",
58
62
  "title-case": "^3.0.3",
59
63
  "validator": "^13.9.0",
60
- "@stacksjs/alias": "0.53.1",
61
- "@stacksjs/types": "0.53.1"
64
+ "@stacksjs/alias": "0.56.23",
65
+ "@stacksjs/types": "0.56.23"
66
+ },
67
+ "dependencies": {
68
+ "macroable": "^7.0.2"
62
69
  },
63
70
  "devDependencies": {
64
- "@stacksjs/development": "0.53.1"
71
+ "@stacksjs/development": "0.56.23"
65
72
  },
66
73
  "scripts": {
67
74
  "build": "unbuild",