@adonisjs/core 6.19.0 → 7.0.0-next.1
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/build/commands/add.d.ts +36 -5
- package/build/commands/add.js +24 -60
- package/build/commands/build.d.ts +23 -3
- package/build/commands/build.js +22 -36
- package/build/commands/commands.json +1 -1
- package/build/commands/configure.d.ts +35 -12
- package/build/commands/configure.js +39 -12
- package/build/commands/eject.d.ts +28 -3
- package/build/commands/eject.js +24 -5
- package/build/commands/env/add.d.ts +41 -4
- package/build/commands/env/add.js +32 -5
- package/build/commands/generate_key.d.ts +20 -1
- package/build/commands/generate_key.js +14 -1
- package/build/commands/inspect_rcfile.d.ts +20 -2
- package/build/commands/inspect_rcfile.js +20 -2
- package/build/commands/list/routes.d.ts +33 -11
- package/build/commands/list/routes.js +28 -5
- package/build/commands/make/command.d.ts +26 -3
- package/build/commands/make/command.js +25 -5
- package/build/commands/make/controller.d.ts +35 -2
- package/build/commands/make/controller.js +20 -2
- package/build/commands/make/event.d.ts +30 -4
- package/build/commands/make/event.js +27 -4
- package/build/commands/make/exception.d.ts +30 -4
- package/build/commands/make/exception.js +27 -4
- package/build/commands/make/listener.d.ts +38 -5
- package/build/commands/make/listener.js +32 -5
- package/build/commands/make/middleware.d.ts +25 -2
- package/build/commands/make/middleware.js +21 -4
- package/build/commands/make/preload.d.ts +31 -4
- package/build/commands/make/preload.js +28 -8
- package/build/commands/make/provider.d.ts +32 -3
- package/build/commands/make/provider.js +29 -7
- package/build/commands/make/service.d.ts +21 -2
- package/build/commands/make/service.js +18 -2
- package/build/commands/make/test.d.ts +27 -4
- package/build/commands/make/test.js +36 -8
- package/build/commands/make/transformer.d.ts +43 -0
- package/build/commands/make/transformer.js +65 -0
- package/build/commands/make/validator.d.ts +36 -5
- package/build/commands/make/validator.js +30 -5
- package/build/commands/make/view.d.ts +26 -3
- package/build/commands/make/view.js +24 -4
- package/build/commands/repl.d.ts +24 -4
- package/build/commands/repl.js +23 -3
- package/build/commands/serve.d.ts +38 -4
- package/build/commands/serve.js +34 -43
- package/build/commands/test.d.ts +68 -7
- package/build/commands/test.js +39 -37
- package/build/factories/core/ace.d.ts +31 -4
- package/build/factories/core/ace.js +20 -4
- package/build/factories/core/ignitor.d.ts +80 -9
- package/build/factories/core/ignitor.js +84 -13
- package/build/factories/core/main.d.ts +3 -3
- package/build/factories/core/main.js +3 -3
- package/build/factories/core/test_utils.d.ts +32 -4
- package/build/factories/core/test_utils.js +21 -4
- package/build/factories/stubs.d.ts +54 -5
- package/build/factories/stubs.js +55 -6
- package/build/index.d.ts +5 -4
- package/build/index.js +13 -9
- package/build/modules/ace/codemods.d.ts +71 -11
- package/build/modules/ace/codemods.js +90 -22
- package/build/modules/ace/commands.d.ts +48 -13
- package/build/modules/ace/commands.js +45 -10
- package/build/modules/ace/create_kernel.d.ts +19 -8
- package/build/modules/ace/create_kernel.js +19 -8
- package/build/modules/ace/kernel.d.ts +18 -4
- package/build/modules/ace/kernel.js +17 -3
- package/build/modules/ace/main.d.ts +3 -3
- package/build/modules/ace/main.js +3 -3
- package/build/modules/dumper/define_config.d.ts +25 -4
- package/build/modules/dumper/define_config.js +23 -2
- package/build/modules/dumper/dumper.d.ts +82 -12
- package/build/modules/dumper/dumper.js +82 -12
- package/build/modules/dumper/errors.d.ts +31 -10
- package/build/modules/dumper/errors.js +28 -7
- package/build/modules/dumper/main.d.ts +3 -3
- package/build/modules/dumper/main.js +3 -3
- package/build/modules/dumper/plugins/edge.d.ts +1 -1
- package/build/modules/hash/define_config.d.ts +53 -8
- package/build/modules/hash/define_config.js +51 -6
- package/build/modules/hash/main.d.ts +1 -1
- package/build/modules/hash/main.js +1 -1
- package/build/modules/http/main.d.ts +1 -1
- package/build/modules/http/main.js +1 -1
- package/build/modules/http/request_validator.d.ts +36 -9
- package/build/modules/http/request_validator.js +32 -5
- package/build/modules/transformers/main.d.ts +1 -0
- package/build/modules/transformers/main.js +9 -0
- package/build/providers/app_provider.d.ts +173 -1
- package/build/providers/app_provider.js +204 -8
- package/build/providers/edge_provider.d.ts +31 -2
- package/build/providers/edge_provider.js +31 -2
- package/build/providers/hash_provider.d.ts +38 -1
- package/build/providers/hash_provider.js +40 -3
- package/build/providers/repl_provider.d.ts +40 -1
- package/build/providers/repl_provider.js +52 -2
- package/build/providers/vinejs_provider.d.ts +32 -5
- package/build/providers/vinejs_provider.js +31 -4
- package/build/services/ace.d.ts +1 -1
- package/build/services/ace.js +1 -1
- package/build/services/app.d.ts +1 -1
- package/build/services/config.d.ts +1 -1
- package/build/services/config.js +1 -1
- package/build/services/dumper.js +1 -1
- package/build/services/emitter.d.ts +1 -1
- package/build/services/emitter.js +1 -1
- package/build/services/encryption.d.ts +1 -1
- package/build/services/encryption.js +1 -1
- package/build/services/hash.d.ts +1 -1
- package/build/services/hash.js +1 -1
- package/build/services/logger.d.ts +1 -1
- package/build/services/logger.js +1 -1
- package/build/services/repl.d.ts +1 -1
- package/build/services/repl.js +1 -1
- package/build/services/router.d.ts +1 -1
- package/build/services/router.js +1 -1
- package/build/services/server.d.ts +1 -1
- package/build/services/server.js +1 -1
- package/build/services/test_utils.d.ts +1 -1
- package/build/services/test_utils.js +1 -1
- package/build/services/url_builder.d.ts +4 -0
- package/build/services/url_builder.js +21 -0
- package/build/src/assembler_hooks/index_entities.d.ts +37 -0
- package/build/src/assembler_hooks/index_entities.js +106 -0
- package/build/src/cli_formatters/routes_list.d.ts +24 -12
- package/build/src/cli_formatters/routes_list.js +43 -46
- package/build/src/config_provider.d.ts +48 -3
- package/build/src/config_provider.js +47 -2
- package/build/src/debug.d.ts +15 -0
- package/build/src/debug.js +15 -0
- package/build/src/exceptions.d.ts +41 -1
- package/build/src/exceptions.js +41 -1
- package/build/src/helpers/assert.d.ts +47 -1
- package/build/src/helpers/assert.js +47 -1
- package/build/src/helpers/is.d.ts +21 -0
- package/build/src/helpers/is.js +21 -0
- package/build/src/helpers/main.d.ts +48 -5
- package/build/src/helpers/main.js +48 -5
- package/build/src/helpers/string.d.ts +89 -9
- package/build/src/helpers/string.js +21 -2
- package/build/src/helpers/types.d.ts +97 -2
- package/build/src/helpers/types.js +96 -2
- package/build/src/helpers/verification_token.d.ts +22 -1
- package/build/src/helpers/verification_token.js +24 -2
- package/build/src/ignitor/ace.d.ts +23 -3
- package/build/src/ignitor/ace.js +21 -1
- package/build/src/ignitor/http.d.ts +16 -3
- package/build/src/ignitor/http.js +16 -3
- package/build/src/ignitor/main.d.ts +29 -6
- package/build/src/ignitor/main.js +30 -7
- package/build/src/ignitor/test.d.ts +26 -3
- package/build/src/ignitor/test.js +24 -1
- package/build/src/test_utils/http.d.ts +19 -3
- package/build/src/test_utils/http.js +24 -3
- package/build/src/test_utils/main.d.ts +22 -4
- package/build/src/test_utils/main.js +21 -3
- package/build/src/types.d.ts +283 -26
- package/build/src/utils.d.ts +60 -0
- package/build/src/utils.js +104 -0
- package/build/src/vine.d.ts +24 -1
- package/build/src/vine.js +27 -1
- package/build/stubs/main.js +1 -2
- package/build/stubs/make/transformer/main.stub +18 -0
- package/build/toolkit/main.js +1 -1
- package/build/types/common.d.ts +1 -0
- package/build/types/common.js +9 -0
- package/build/types/helpers.d.ts +2 -1
- package/build/types/http.d.ts +1 -0
- package/build/types/transformers.d.ts +1 -0
- package/build/types/transformers.js +9 -0
- package/package.json +55 -52
- package/build/src/helpers/parse_binding_reference.d.ts +0 -45
- package/build/src/helpers/parse_binding_reference.js +0 -83
- package/build/src/internal_helpers.d.ts +0 -15
- package/build/src/internal_helpers.js +0 -63
|
@@ -6,4 +6,50 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Assertion utilities for type-safe programming in AdonisJS. These functions
|
|
11
|
+
* provide runtime type assertions that help with TypeScript type narrowing
|
|
12
|
+
* and catching potential null/undefined issues early.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Type-safe null checking
|
|
16
|
+
* import { assertExists } from '@adonisjs/core/helpers'
|
|
17
|
+
*
|
|
18
|
+
* function processUser(user: User | null) {
|
|
19
|
+
* assertExists(user) // TypeScript now knows user is not null
|
|
20
|
+
* console.log(user.name) // Safe to access properties
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Exhaustiveness checking in switch statements
|
|
25
|
+
* import { assertUnreachable } from '@adonisjs/core/helpers'
|
|
26
|
+
*
|
|
27
|
+
* function handleStatus(status: 'pending' | 'completed') {
|
|
28
|
+
* switch (status) {
|
|
29
|
+
* case 'pending': return 'Processing...'
|
|
30
|
+
* case 'completed': return 'Done!'
|
|
31
|
+
* default: return assertUnreachable(status)
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
*/
|
|
35
|
+
export {
|
|
36
|
+
/**
|
|
37
|
+
* Assert that a value exists (is not null or undefined).
|
|
38
|
+
* Throws an error if the value is null or undefined.
|
|
39
|
+
*/
|
|
40
|
+
assertExists,
|
|
41
|
+
/**
|
|
42
|
+
* Assert that a value is not null.
|
|
43
|
+
* Throws an error if the value is null.
|
|
44
|
+
*/
|
|
45
|
+
assertNotNull,
|
|
46
|
+
/**
|
|
47
|
+
* Assert that a value is defined (is not undefined).
|
|
48
|
+
* Throws an error if the value is undefined.
|
|
49
|
+
*/
|
|
50
|
+
assertIsDefined,
|
|
51
|
+
/**
|
|
52
|
+
* Assert that code should never reach this point.
|
|
53
|
+
* Useful for exhaustiveness checking in switch statements.
|
|
54
|
+
*/
|
|
55
|
+
assertUnreachable, } from '@poppinss/utils/assert';
|
|
@@ -1,2 +1,23 @@
|
|
|
1
1
|
import is from '@sindresorhus/is';
|
|
2
|
+
/**
|
|
3
|
+
* Type checking utilities re-exported from @sindresorhus/is. Provides
|
|
4
|
+
* a comprehensive set of type-checking functions with TypeScript type guards.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Basic type checking
|
|
8
|
+
* import { is } from '@adonisjs/core/helpers'
|
|
9
|
+
*
|
|
10
|
+
* if (is.string(value)) {
|
|
11
|
+
* // TypeScript knows value is string
|
|
12
|
+
* console.log(value.toUpperCase())
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Complex type checking
|
|
17
|
+
* import { is } from '@adonisjs/core/helpers'
|
|
18
|
+
*
|
|
19
|
+
* is.array(value) && is.nonEmptyArray(value)
|
|
20
|
+
* is.plainObject(obj) && is.hasProperty(obj, 'name')
|
|
21
|
+
* is.number(num) && is.integer(num) && is.positive(num)
|
|
22
|
+
*/
|
|
2
23
|
export default is;
|
package/build/src/helpers/is.js
CHANGED
|
@@ -7,4 +7,25 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import is from '@sindresorhus/is';
|
|
10
|
+
/**
|
|
11
|
+
* Type checking utilities re-exported from @sindresorhus/is. Provides
|
|
12
|
+
* a comprehensive set of type-checking functions with TypeScript type guards.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Basic type checking
|
|
16
|
+
* import { is } from '@adonisjs/core/helpers'
|
|
17
|
+
*
|
|
18
|
+
* if (is.string(value)) {
|
|
19
|
+
* // TypeScript knows value is string
|
|
20
|
+
* console.log(value.toUpperCase())
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Complex type checking
|
|
25
|
+
* import { is } from '@adonisjs/core/helpers'
|
|
26
|
+
*
|
|
27
|
+
* is.array(value) && is.nonEmptyArray(value)
|
|
28
|
+
* is.plainObject(obj) && is.hasProperty(obj, 'name')
|
|
29
|
+
* is.number(num) && is.integer(num) && is.positive(num)
|
|
30
|
+
*/
|
|
10
31
|
export default is;
|
|
@@ -1,5 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Core helper utilities for AdonisJS applications. This module provides
|
|
3
|
+
* a collection of commonly used utilities including file system operations,
|
|
4
|
+
* cryptographic functions, composition utilities, and HTTP server helpers.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // File system utilities
|
|
8
|
+
* import { fsReadAll, fsImportAll } from '@adonisjs/core/helpers'
|
|
9
|
+
*
|
|
10
|
+
* const files = await fsReadAll(url('app/controllers'))
|
|
11
|
+
* const modules = await fsImportAll(url('app/events'))
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Cryptographic utilities
|
|
15
|
+
* import { base64, safeEqual, Secret } from '@adonisjs/core/helpers'
|
|
16
|
+
*
|
|
17
|
+
* const encoded = base64.encode('sensitive data')
|
|
18
|
+
* const isEqual = safeEqual(hash1, hash2)
|
|
19
|
+
* const secret = new Secret('my-secret-key')
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // HTTP server helpers
|
|
23
|
+
* import { middlewareInfo, routeInfo } from '@adonisjs/core/helpers'
|
|
24
|
+
*
|
|
25
|
+
* const middleware = middlewareInfo('cors', () => {})
|
|
26
|
+
* const route = routeInfo('users.show', '/users/:id')
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* File system utilities for reading and importing files recursively.
|
|
30
|
+
*/
|
|
31
|
+
export { fsReadAll, fsImportAll } from '@poppinss/utils/fs';
|
|
32
|
+
/**
|
|
33
|
+
* Base64 encoding and decoding utilities.
|
|
34
|
+
*/
|
|
35
|
+
export { default as base64 } from '@poppinss/utils/base64';
|
|
36
|
+
/**
|
|
37
|
+
* Core utilities including function composition, secret management,
|
|
38
|
+
* safe equality comparison, and message building.
|
|
39
|
+
*/
|
|
40
|
+
export { compose, Secret, safeEqual, MessageBuilder } from '@poppinss/utils';
|
|
41
|
+
/**
|
|
42
|
+
* Verification token utility for creating secure tokens.
|
|
43
|
+
*/
|
|
44
|
+
export { VerificationToken } from './verification_token.ts';
|
|
45
|
+
/**
|
|
46
|
+
* HTTP server helper functions for middleware and route information.
|
|
47
|
+
*/
|
|
48
|
+
export { middlewareInfo, routeInfo } from '@adonisjs/http-server/helpers';
|
|
@@ -6,8 +6,51 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Core helper utilities for AdonisJS applications. This module provides
|
|
11
|
+
* a collection of commonly used utilities including file system operations,
|
|
12
|
+
* cryptographic functions, composition utilities, and HTTP server helpers.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // File system utilities
|
|
16
|
+
* import { fsReadAll, fsImportAll } from '@adonisjs/core/helpers'
|
|
17
|
+
*
|
|
18
|
+
* const files = await fsReadAll(url('app/controllers'))
|
|
19
|
+
* const modules = await fsImportAll(url('app/events'))
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Cryptographic utilities
|
|
23
|
+
* import { base64, safeEqual, Secret } from '@adonisjs/core/helpers'
|
|
24
|
+
*
|
|
25
|
+
* const encoded = base64.encode('sensitive data')
|
|
26
|
+
* const isEqual = safeEqual(hash1, hash2)
|
|
27
|
+
* const secret = new Secret('my-secret-key')
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // HTTP server helpers
|
|
31
|
+
* import { middlewareInfo, routeInfo } from '@adonisjs/core/helpers'
|
|
32
|
+
*
|
|
33
|
+
* const middleware = middlewareInfo('cors', () => {})
|
|
34
|
+
* const route = routeInfo('users.show', '/users/:id')
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* File system utilities for reading and importing files recursively.
|
|
38
|
+
*/
|
|
39
|
+
export { fsReadAll, fsImportAll } from '@poppinss/utils/fs';
|
|
40
|
+
/**
|
|
41
|
+
* Base64 encoding and decoding utilities.
|
|
42
|
+
*/
|
|
43
|
+
export { default as base64 } from '@poppinss/utils/base64';
|
|
44
|
+
/**
|
|
45
|
+
* Core utilities including function composition, secret management,
|
|
46
|
+
* safe equality comparison, and message building.
|
|
47
|
+
*/
|
|
48
|
+
export { compose, Secret, safeEqual, MessageBuilder } from '@poppinss/utils';
|
|
49
|
+
/**
|
|
50
|
+
* Verification token utility for creating secure tokens.
|
|
51
|
+
*/
|
|
52
|
+
export { VerificationToken } from "./verification_token.js";
|
|
53
|
+
/**
|
|
54
|
+
* HTTP server helper functions for middleware and route information.
|
|
55
|
+
*/
|
|
56
|
+
export { middlewareInfo, routeInfo } from '@adonisjs/http-server/helpers';
|
|
@@ -1,42 +1,122 @@
|
|
|
1
|
-
import { EncodeOptions } from 'he';
|
|
2
1
|
import string from '@poppinss/utils/string';
|
|
2
|
+
import { type EncodeOptions } from 'he';
|
|
3
3
|
import StringBuilder from '@poppinss/utils/string_builder';
|
|
4
4
|
/**
|
|
5
|
-
* Collection of string helpers to transform a string value.
|
|
5
|
+
* Collection of string helpers to transform a string value. This object extends
|
|
6
|
+
* the base string utilities from @poppinss/utils with additional AdonisJS-specific
|
|
7
|
+
* string manipulation methods.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Basic string transformations
|
|
11
|
+
* stringHelpers.camelCase('hello_world') // 'helloWorld'
|
|
12
|
+
* stringHelpers.snakeCase('HelloWorld') // 'hello_world'
|
|
13
|
+
* stringHelpers.pascalCase('hello world') // 'HelloWorld'
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // HTML escaping and encoding
|
|
17
|
+
* stringHelpers.escapeHTML('<script>alert("xss")</script>')
|
|
18
|
+
* stringHelpers.encodeSymbols('© 2023 AdonisJS')
|
|
6
19
|
*/
|
|
7
20
|
declare const stringHelpers: typeof string & {
|
|
8
21
|
/**
|
|
9
|
-
* Creates an instance of the string
|
|
22
|
+
* Creates an instance of the StringBuilder for efficient string concatenation.
|
|
23
|
+
*
|
|
24
|
+
* @param value - Initial string value or existing StringBuilder instance
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const builder = stringHelpers.create('Hello')
|
|
28
|
+
* builder.append(' ').append('World')
|
|
29
|
+
* console.log(builder.toString()) // 'Hello World'
|
|
10
30
|
*/
|
|
11
31
|
create(value: string | StringBuilder): StringBuilder;
|
|
32
|
+
/**
|
|
33
|
+
* Convert a number to its ordinal form (1st, 2nd, 3rd, etc.).
|
|
34
|
+
* Alias for the `ordinal` method from @poppinss/utils.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* stringHelpers.ordinalize(1) // '1st'
|
|
38
|
+
* stringHelpers.ordinalize(22) // '22nd'
|
|
39
|
+
*/
|
|
12
40
|
ordinalize: (typeof string)['ordinal'];
|
|
13
41
|
/**
|
|
14
|
-
* Convert a string to a sentence
|
|
42
|
+
* Convert a string to a readable sentence format.
|
|
43
|
+
* Alias for the `sentence` method from @poppinss/utils.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* stringHelpers.toSentence('hello_world') // 'Hello world'
|
|
47
|
+
* stringHelpers.toSentence('firstName') // 'First name'
|
|
15
48
|
*/
|
|
16
49
|
toSentence: (typeof string)['sentence'];
|
|
17
50
|
/**
|
|
18
|
-
* Generate a random string
|
|
51
|
+
* Generate a cryptographically secure random string of specified length.
|
|
52
|
+
* Alias for the `random` method from @poppinss/utils.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* stringHelpers.generateRandom(16) // 'a1b2c3d4e5f6g7h8'
|
|
56
|
+
* stringHelpers.generateRandom(32) // Long random string
|
|
19
57
|
*/
|
|
20
58
|
generateRandom: (typeof string)['random'];
|
|
21
59
|
/**
|
|
22
|
-
*
|
|
60
|
+
* Convert high-resolution time difference to a human-readable format.
|
|
61
|
+
*
|
|
62
|
+
* @param time - High-resolution time tuple from process.hrtime()
|
|
63
|
+
* @param options - Formatting options
|
|
64
|
+
* @param options.verbose - Use verbose format (e.g., '1 second' vs '1s')
|
|
65
|
+
* @param options.precise - Show precise decimal places
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const start = process.hrtime()
|
|
69
|
+
* // ... some operation
|
|
70
|
+
* const diff = process.hrtime(start)
|
|
71
|
+
* stringHelpers.prettyHrTime(diff) // '2.5ms'
|
|
72
|
+
* stringHelpers.prettyHrTime(diff, { verbose: true }) // '2 milliseconds'
|
|
23
73
|
*/
|
|
24
74
|
prettyHrTime(time: [number, number], options?: {
|
|
25
75
|
verbose?: boolean | undefined;
|
|
26
76
|
precise?: boolean | undefined;
|
|
27
77
|
}): string;
|
|
28
78
|
/**
|
|
29
|
-
* Check if a string is empty.
|
|
79
|
+
* Check if a string is empty or contains only whitespace characters.
|
|
80
|
+
*
|
|
81
|
+
* @param value - The string to check
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* stringHelpers.isEmpty('') // true
|
|
85
|
+
* stringHelpers.isEmpty(' ') // true
|
|
86
|
+
* stringHelpers.isEmpty('hello') // false
|
|
30
87
|
*/
|
|
31
88
|
isEmpty(value: string): boolean;
|
|
32
89
|
/**
|
|
33
|
-
* Escape HTML entities
|
|
90
|
+
* Escape HTML entities to prevent XSS attacks and display HTML safely.
|
|
91
|
+
*
|
|
92
|
+
* @param value - The string to escape
|
|
93
|
+
* @param options - Escaping options
|
|
94
|
+
* @param options.encodeSymbols - Whether to encode symbols as HTML entities
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* stringHelpers.escapeHTML('<script>alert("xss")</script>')
|
|
98
|
+
* // '<script>alert("xss")</script>'
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* stringHelpers.escapeHTML('© 2023', { encodeSymbols: true })
|
|
102
|
+
* // '© 2023'
|
|
34
103
|
*/
|
|
35
104
|
escapeHTML(value: string, options?: {
|
|
36
105
|
encodeSymbols?: boolean;
|
|
37
106
|
}): string;
|
|
38
107
|
/**
|
|
39
|
-
* Encode symbols
|
|
108
|
+
* Encode Unicode symbols and special characters as HTML entities.
|
|
109
|
+
*
|
|
110
|
+
* @param value - The string containing symbols to encode
|
|
111
|
+
* @param options - Encoding options from the 'he' library
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* stringHelpers.encodeSymbols('© 2023 AdonisJS ™')
|
|
115
|
+
* // '© 2023 AdonisJS ™'
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* stringHelpers.encodeSymbols('Café', { decimal: true })
|
|
119
|
+
* // 'Café'
|
|
40
120
|
*/
|
|
41
121
|
encodeSymbols(value: string, options?: EncodeOptions): string;
|
|
42
122
|
};
|
|
@@ -6,12 +6,25 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import he from 'he';
|
|
10
9
|
import prettyHrTime from 'pretty-hrtime';
|
|
11
10
|
import string from '@poppinss/utils/string';
|
|
11
|
+
import he from 'he';
|
|
12
12
|
import StringBuilder from '@poppinss/utils/string_builder';
|
|
13
13
|
/**
|
|
14
|
-
* Collection of string helpers to transform a string value.
|
|
14
|
+
* Collection of string helpers to transform a string value. This object extends
|
|
15
|
+
* the base string utilities from @poppinss/utils with additional AdonisJS-specific
|
|
16
|
+
* string manipulation methods.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Basic string transformations
|
|
20
|
+
* stringHelpers.camelCase('hello_world') // 'helloWorld'
|
|
21
|
+
* stringHelpers.snakeCase('HelloWorld') // 'hello_world'
|
|
22
|
+
* stringHelpers.pascalCase('hello world') // 'HelloWorld'
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // HTML escaping and encoding
|
|
26
|
+
* stringHelpers.escapeHTML('<script>alert("xss")</script>')
|
|
27
|
+
* stringHelpers.encodeSymbols('© 2023 AdonisJS')
|
|
15
28
|
*/
|
|
16
29
|
const stringHelpers = {
|
|
17
30
|
...string,
|
|
@@ -21,6 +34,12 @@ const stringHelpers = {
|
|
|
21
34
|
create(value) {
|
|
22
35
|
return new StringBuilder(value);
|
|
23
36
|
},
|
|
37
|
+
/**
|
|
38
|
+
* Formats Node.js hrtime output into a human-readable string.
|
|
39
|
+
*
|
|
40
|
+
* @param time - Tuple of [seconds, nanoseconds] from process.hrtime()
|
|
41
|
+
* @param options - Formatting options for output style and precision
|
|
42
|
+
*/
|
|
24
43
|
prettyHrTime(time, options) {
|
|
25
44
|
return prettyHrTime(time, options);
|
|
26
45
|
},
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @deprecated
|
|
3
|
-
* Use "is" helpers instead. The types helpers
|
|
4
|
-
*
|
|
3
|
+
* Use "is" helpers instead. The types helpers exist for backward compatibility.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Instead of using types helpers (deprecated)
|
|
7
|
+
* types.isString('hello')
|
|
8
|
+
* types.isNumber(42)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Use the new "is" helpers
|
|
12
|
+
* import { is } from '@adonisjs/core/helpers'
|
|
13
|
+
* is.string('hello')
|
|
14
|
+
* is.number(42)
|
|
5
15
|
*/
|
|
6
16
|
declare const types: {
|
|
17
|
+
/**
|
|
18
|
+
* Direct reference to the is utility for type checking lookups.
|
|
19
|
+
* @deprecated Use the is helpers directly instead
|
|
20
|
+
*/
|
|
7
21
|
lookup: ((value: unknown) => import("@sindresorhus/is").TypeName) & {
|
|
8
22
|
all: typeof import("@sindresorhus/is").isAll;
|
|
9
23
|
any: typeof import("@sindresorhus/is").isAny;
|
|
@@ -90,6 +104,7 @@ declare const types: {
|
|
|
90
104
|
urlInstance: typeof import("@sindresorhus/is").isUrlInstance;
|
|
91
105
|
urlSearchParams: typeof import("@sindresorhus/is").isUrlSearchParams;
|
|
92
106
|
urlString: typeof import("@sindresorhus/is").isUrlString;
|
|
107
|
+
optional: typeof import("@sindresorhus/is").isOptional;
|
|
93
108
|
validDate: typeof import("@sindresorhus/is").isValidDate;
|
|
94
109
|
validLength: typeof import("@sindresorhus/is").isValidLength;
|
|
95
110
|
weakMap: typeof import("@sindresorhus/is").isWeakMap;
|
|
@@ -97,21 +112,101 @@ declare const types: {
|
|
|
97
112
|
weakSet: typeof import("@sindresorhus/is").isWeakSet;
|
|
98
113
|
whitespaceString: typeof import("@sindresorhus/is").isWhitespaceString;
|
|
99
114
|
};
|
|
115
|
+
/**
|
|
116
|
+
* Check if value is null.
|
|
117
|
+
* @deprecated Use is.null instead
|
|
118
|
+
*/
|
|
100
119
|
isNull: typeof import("@sindresorhus/is").isNull;
|
|
120
|
+
/**
|
|
121
|
+
* Check if value is a boolean.
|
|
122
|
+
* @deprecated Use is.boolean instead
|
|
123
|
+
*/
|
|
101
124
|
isBoolean: typeof import("@sindresorhus/is").isBoolean;
|
|
125
|
+
/**
|
|
126
|
+
* Check if value is a Buffer.
|
|
127
|
+
* @deprecated Use is.buffer instead
|
|
128
|
+
*/
|
|
102
129
|
isBuffer: typeof import("@sindresorhus/is").isBuffer;
|
|
130
|
+
/**
|
|
131
|
+
* Check if value is a number.
|
|
132
|
+
* @deprecated Use is.number instead
|
|
133
|
+
*/
|
|
103
134
|
isNumber: typeof import("@sindresorhus/is").isNumber;
|
|
135
|
+
/**
|
|
136
|
+
* Check if value is a string.
|
|
137
|
+
* @deprecated Use is.string instead
|
|
138
|
+
*/
|
|
104
139
|
isString: typeof import("@sindresorhus/is").isString;
|
|
140
|
+
/**
|
|
141
|
+
* Check if value is an arguments object.
|
|
142
|
+
* @deprecated Use is.arguments instead
|
|
143
|
+
*/
|
|
105
144
|
isArguments: any;
|
|
145
|
+
/**
|
|
146
|
+
* Check if value is an object.
|
|
147
|
+
* @deprecated Use is.object instead
|
|
148
|
+
*/
|
|
106
149
|
isObject: typeof import("@sindresorhus/is").isObject;
|
|
150
|
+
/**
|
|
151
|
+
* Check if value is a Date.
|
|
152
|
+
* @deprecated Use is.date instead
|
|
153
|
+
*/
|
|
107
154
|
isDate: typeof import("@sindresorhus/is").isDate;
|
|
155
|
+
/**
|
|
156
|
+
* Check if value is an array.
|
|
157
|
+
* @deprecated Use is.array instead
|
|
158
|
+
*/
|
|
108
159
|
isArray: typeof import("@sindresorhus/is").isArray;
|
|
160
|
+
/**
|
|
161
|
+
* Check if value is a regular expression.
|
|
162
|
+
* @deprecated Use is.regExp instead
|
|
163
|
+
*/
|
|
109
164
|
isRegexp: typeof import("@sindresorhus/is").isRegExp;
|
|
165
|
+
/**
|
|
166
|
+
* Check if value is an error object.
|
|
167
|
+
* @deprecated Use is.error instead
|
|
168
|
+
*/
|
|
110
169
|
isError: typeof import("@sindresorhus/is").isError;
|
|
170
|
+
/**
|
|
171
|
+
* Check if value is a function.
|
|
172
|
+
* @deprecated Use is.function instead
|
|
173
|
+
*/
|
|
111
174
|
isFunction: typeof import("@sindresorhus/is").isFunction;
|
|
175
|
+
/**
|
|
176
|
+
* Check if value is a class.
|
|
177
|
+
* @deprecated Use is.class instead
|
|
178
|
+
*/
|
|
112
179
|
isClass: typeof import("@sindresorhus/is").isClass;
|
|
180
|
+
/**
|
|
181
|
+
* Check if value is an integer.
|
|
182
|
+
* @deprecated Use is.integer instead
|
|
183
|
+
*/
|
|
113
184
|
isInteger: typeof import("@sindresorhus/is").isInteger;
|
|
185
|
+
/**
|
|
186
|
+
* Check if a number is a float (has decimal places).
|
|
187
|
+
*
|
|
188
|
+
* @param value - The number to check
|
|
189
|
+
* @deprecated Use is.decimal or custom logic instead
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* types.isFloat(3.14) // true
|
|
193
|
+
* types.isFloat(42) // false
|
|
194
|
+
*/
|
|
114
195
|
isFloat(value: number): value is number;
|
|
196
|
+
/**
|
|
197
|
+
* Check if a value represents a decimal number with specific decimal places.
|
|
198
|
+
*
|
|
199
|
+
* @param value - The value to check (string or number)
|
|
200
|
+
* @param options - Options for decimal validation
|
|
201
|
+
* @param options.decimalPlaces - Regex pattern for allowed decimal places (default: '1,')
|
|
202
|
+
* @deprecated Use a validation library like Vine or custom logic instead
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* types.isDecimal('3.14') // true
|
|
206
|
+
* types.isDecimal('42.0') // true
|
|
207
|
+
* types.isDecimal('42') // false
|
|
208
|
+
* types.isDecimal('3.141', { decimalPlaces: '1,3' }) // true
|
|
209
|
+
*/
|
|
115
210
|
isDecimal(value: string | number, options?: {
|
|
116
211
|
decimalPlaces?: string;
|
|
117
212
|
}): boolean;
|
|
@@ -9,28 +9,122 @@
|
|
|
9
9
|
import is from '@sindresorhus/is';
|
|
10
10
|
/**
|
|
11
11
|
* @deprecated
|
|
12
|
-
* Use "is" helpers instead. The types helpers
|
|
13
|
-
*
|
|
12
|
+
* Use "is" helpers instead. The types helpers exist for backward compatibility.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Instead of using types helpers (deprecated)
|
|
16
|
+
* types.isString('hello')
|
|
17
|
+
* types.isNumber(42)
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Use the new "is" helpers
|
|
21
|
+
* import { is } from '@adonisjs/core/helpers'
|
|
22
|
+
* is.string('hello')
|
|
23
|
+
* is.number(42)
|
|
14
24
|
*/
|
|
15
25
|
const types = {
|
|
26
|
+
/**
|
|
27
|
+
* Direct reference to the is utility for type checking lookups.
|
|
28
|
+
* @deprecated Use the is helpers directly instead
|
|
29
|
+
*/
|
|
16
30
|
lookup: is,
|
|
31
|
+
/**
|
|
32
|
+
* Check if value is null.
|
|
33
|
+
* @deprecated Use is.null instead
|
|
34
|
+
*/
|
|
17
35
|
isNull: is.null,
|
|
36
|
+
/**
|
|
37
|
+
* Check if value is a boolean.
|
|
38
|
+
* @deprecated Use is.boolean instead
|
|
39
|
+
*/
|
|
18
40
|
isBoolean: is.boolean,
|
|
41
|
+
/**
|
|
42
|
+
* Check if value is a Buffer.
|
|
43
|
+
* @deprecated Use is.buffer instead
|
|
44
|
+
*/
|
|
19
45
|
isBuffer: is.buffer,
|
|
46
|
+
/**
|
|
47
|
+
* Check if value is a number.
|
|
48
|
+
* @deprecated Use is.number instead
|
|
49
|
+
*/
|
|
20
50
|
isNumber: is.number,
|
|
51
|
+
/**
|
|
52
|
+
* Check if value is a string.
|
|
53
|
+
* @deprecated Use is.string instead
|
|
54
|
+
*/
|
|
21
55
|
isString: is.string,
|
|
56
|
+
/**
|
|
57
|
+
* Check if value is an arguments object.
|
|
58
|
+
* @deprecated Use is.arguments instead
|
|
59
|
+
*/
|
|
22
60
|
isArguments: is.arguments,
|
|
61
|
+
/**
|
|
62
|
+
* Check if value is an object.
|
|
63
|
+
* @deprecated Use is.object instead
|
|
64
|
+
*/
|
|
23
65
|
isObject: is.object,
|
|
66
|
+
/**
|
|
67
|
+
* Check if value is a Date.
|
|
68
|
+
* @deprecated Use is.date instead
|
|
69
|
+
*/
|
|
24
70
|
isDate: is.date,
|
|
71
|
+
/**
|
|
72
|
+
* Check if value is an array.
|
|
73
|
+
* @deprecated Use is.array instead
|
|
74
|
+
*/
|
|
25
75
|
isArray: is.array,
|
|
76
|
+
/**
|
|
77
|
+
* Check if value is a regular expression.
|
|
78
|
+
* @deprecated Use is.regExp instead
|
|
79
|
+
*/
|
|
26
80
|
isRegexp: is.regExp,
|
|
81
|
+
/**
|
|
82
|
+
* Check if value is an error object.
|
|
83
|
+
* @deprecated Use is.error instead
|
|
84
|
+
*/
|
|
27
85
|
isError: is.error,
|
|
86
|
+
/**
|
|
87
|
+
* Check if value is a function.
|
|
88
|
+
* @deprecated Use is.function instead
|
|
89
|
+
*/
|
|
28
90
|
isFunction: is.function,
|
|
91
|
+
/**
|
|
92
|
+
* Check if value is a class.
|
|
93
|
+
* @deprecated Use is.class instead
|
|
94
|
+
*/
|
|
29
95
|
isClass: is.class,
|
|
96
|
+
/**
|
|
97
|
+
* Check if value is an integer.
|
|
98
|
+
* @deprecated Use is.integer instead
|
|
99
|
+
*/
|
|
30
100
|
isInteger: is.integer,
|
|
101
|
+
/**
|
|
102
|
+
* Check if a number is a float (has decimal places).
|
|
103
|
+
*
|
|
104
|
+
* @param value - The number to check
|
|
105
|
+
* @deprecated Use is.decimal or custom logic instead
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* types.isFloat(3.14) // true
|
|
109
|
+
* types.isFloat(42) // false
|
|
110
|
+
*/
|
|
31
111
|
isFloat(value) {
|
|
32
112
|
return value !== (value | 0);
|
|
33
113
|
},
|
|
114
|
+
/**
|
|
115
|
+
* Check if a value represents a decimal number with specific decimal places.
|
|
116
|
+
*
|
|
117
|
+
* @param value - The value to check (string or number)
|
|
118
|
+
* @param options - Options for decimal validation
|
|
119
|
+
* @param options.decimalPlaces - Regex pattern for allowed decimal places (default: '1,')
|
|
120
|
+
* @deprecated Use a validation library like Vine or custom logic instead
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* types.isDecimal('3.14') // true
|
|
124
|
+
* types.isDecimal('42.0') // true
|
|
125
|
+
* types.isDecimal('42') // false
|
|
126
|
+
* types.isDecimal('3.141', { decimalPlaces: '1,3' }) // true
|
|
127
|
+
*/
|
|
34
128
|
isDecimal(value, options) {
|
|
35
129
|
if (typeof value === 'number') {
|
|
36
130
|
value = value.toString();
|