@orieljs/support 0.1.0-alpha.1 → 0.1.0-alpha.11

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/NOTICE CHANGED
@@ -7,3 +7,10 @@ This product includes software developed by the Oriel project
7
7
  Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
8
8
  The Oriel name and logo are not covered by that license; see TRADEMARKS.md
9
9
  (https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
10
+
11
+ @orieljs/support (and @orieljs/framework, which bundles it) includes transliteration data from
12
+ voku/portable-ascii (https://github.com/voku/portable-ascii), Copyright (C) 2019 Lars Moelleken, MIT License.
13
+
14
+ @orieljs/notifications (and @orieljs/framework, which bundles it) includes the HTML and CSS of
15
+ Laravel's default notification mail (laravel/framework, https://github.com/laravel/framework),
16
+ Copyright (c) Taylor Otwell, MIT License.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @orieljs/support
2
+
3
+ The helpers the rest of Oriel is built on: `Str`, `Arr`, service providers, facades and global helpers, as Laravel's `Illuminate\Support`. It is part of `@orieljs/framework`, which every Oriel app already installs, and is re-exported from it. In an app, import it from `@orieljs/framework`; `@orieljs/support` is also published on its own.
4
+
5
+ ```bash
6
+ npm install @orieljs/framework
7
+ ```
8
+
9
+ ```ts title="app/Support/posts.ts"
10
+ import { Str, collect } from '@orieljs/framework'
11
+ import type { Post } from '../Models/Post'
12
+
13
+ export function card(post: Post) {
14
+ return {
15
+ title: Str.of(post.title).trim().title().toString(),
16
+ excerpt: Str.limit(post.body, 120),
17
+ url: `/posts/${Str.slug(post.title)}`,
18
+ }
19
+ }
20
+
21
+ export function authorIds(posts: Post[]): number[] {
22
+ return collect(posts).pluck('author_id').unique().all()
23
+ }
24
+ ```
25
+
26
+ `Str` has Laravel's string helpers (`slug()`, `limit()`, `plural()`, `uuid()`, …), and `Str.of()` chains them. `Arr` reads and writes nested values by dotted key (`get()`, `set()`, `has()`), flattens them with `dot()` and picks keys with `only()`. `ServiceProvider` and `facade()` are the base of every component, and the helpers are `app()`, `config()`, `collect()`, `now()`, the async `retry()`, `tap()`, `value()` and `__()`.
27
+
28
+ Documentation: https://orieljs.vercel.app/docs/helpers
29
+
30
+ Status: early alpha. APIs will change.
31
+
32
+ ## License
33
+
34
+ Oriel is open-source software licensed under the Apache License 2.0 (Apache-2.0; see `LICENSE` and `NOTICE`). The Oriel name and logo are trademarks; see `TRADEMARKS.md`.
35
+
36
+ Website: https://orieljs.vercel.app
package/TRADEMARKS.md ADDED
@@ -0,0 +1,33 @@
1
+ # Oriel trademark policy
2
+
3
+ The Oriel code is open source under the Apache License 2.0. The **Oriel name and logo** are not: the license covers
4
+ the code only (section 6 of the license says so), and the name and logo stay with the project. This page explains
5
+ what you can and can't do with them. The goal is simple: people should always be able to tell what is the real Oriel
6
+ and what isn't.
7
+
8
+ ## You can, without asking
9
+
10
+ - Use, change, ship and sell the code, as the license allows.
11
+ - Say that your app or package is "built with Oriel", "for Oriel" or "compatible with Oriel".
12
+ - Name a package `oriel-<something>` or `<something>-for-oriel` when it works with Oriel, as long as it is clear that
13
+ it is not official (for example, don't publish it under the `@orieljs` npm scope).
14
+ - Use the name and logo to write about Oriel, teach it, or link to it, in articles, talks, videos and courses.
15
+ - Use the unmodified logo to point to the project, as it is (no recolouring, cropping or
16
+ distortion).
17
+
18
+ ## You can't, without written permission
19
+
20
+ - Call a fork, a modified copy or a competing product "Oriel", or anything likely to be confused with it.
21
+ - Use the name or logo as the name, logo or domain of your own product, company or service.
22
+ - Suggest that the Oriel project made, endorses or supports your work when it doesn't.
23
+ - Sell merchandise with the name or logo.
24
+
25
+ ## Forks
26
+
27
+ Forks are welcome. Please give yours a different name and logo, keep the `LICENSE` and `NOTICE` files, and say that
28
+ it is based on Oriel.
29
+
30
+ ## Questions
31
+
32
+ Open an issue at https://github.com/orieljs/framework or email meeeet.dev@gmail.com. If you're unsure whether a use
33
+ is fine, ask; the answer is usually yes.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,72 @@
1
- import { ServiceProvider as ServiceProvider$1, Application, Abstract, ClassRegistry as ClassRegistry$1, Class, ConfigRepository } from '@orieljs/contracts';
1
+ import { Collection } from '@orieljs/collections';
2
2
  export { collect } from '@orieljs/collections';
3
+ import { ServiceProvider as ServiceProvider$1, Application, Abstract, ClassRegistry as ClassRegistry$1, Class, ConfigRepository } from '@orieljs/contracts';
4
+
5
+ /**
6
+ * Laravel's Stringable: a string with Str's helpers as chainable methods, each returning a new Stringable.
7
+ * `Str.of(' Café ').trim().slug().toString()` is 'cafe'; `request().string('q')` returns one. It prints as its string.
8
+ */
9
+ declare class Stringable {
10
+ #private;
11
+ constructor(value?: string);
12
+ after(search: string): Stringable;
13
+ afterLast(search: string): Stringable;
14
+ append(...values: string[]): Stringable;
15
+ ascii(): Stringable;
16
+ before(search: string): Stringable;
17
+ beforeLast(search: string): Stringable;
18
+ between(from: string, to: string): Stringable;
19
+ camel(): Stringable;
20
+ contains(needles: string | string[]): boolean;
21
+ endsWith(needles: string | string[]): boolean;
22
+ /** The same string as `value` (a string or another Stringable). */
23
+ exactly(value: string | Stringable): boolean;
24
+ /** The parts between the delimiters, as a Collection (PHP's explode()). */
25
+ explode(delimiter: string): Collection<string>;
26
+ finish(cap: string): Stringable;
27
+ /** Wildcard match, as Str.is(): `*` matches anything. */
28
+ is(pattern: string): boolean;
29
+ isEmpty(): boolean;
30
+ isNotEmpty(): boolean;
31
+ kebab(): Stringable;
32
+ lcfirst(): Stringable;
33
+ /** The number of characters (code points, as PHP's mb_strlen()). */
34
+ length(): number;
35
+ limit(limit?: number, end?: string): Stringable;
36
+ lower(): Stringable;
37
+ /** Strips whitespace and invisible characters from the start, or the characters given. */
38
+ ltrim(characters?: string): Stringable;
39
+ plural(count?: number): Stringable;
40
+ prepend(...values: string[]): Stringable;
41
+ /** Replaces every occurrence of the search string (or of each of several) with `replace`. */
42
+ replace(search: string | string[], replace: string): Stringable;
43
+ /** Strips whitespace and invisible characters from the end, or the characters given. */
44
+ rtrim(characters?: string): Stringable;
45
+ singular(): Stringable;
46
+ slug(separator?: string): Stringable;
47
+ snake(delimiter?: string): Stringable;
48
+ start(prefix: string): Stringable;
49
+ startsWith(needles: string | string[]): boolean;
50
+ studly(): Stringable;
51
+ title(): Stringable;
52
+ /** PHP's filter_var(FILTER_VALIDATE_BOOLEAN): '1', 'true', 'on' and 'yes' (any case, trimmed) are true. */
53
+ toBoolean(): boolean;
54
+ /** PHP's floatval(): the leading number, else 0. */
55
+ toFloat(): number;
56
+ /** PHP's intval(): the leading digits, else 0. */
57
+ toInteger(): number;
58
+ toJSON(): string;
59
+ toString(): string;
60
+ /** Strips whitespace and invisible characters from both ends (Laravel's Str::trim()), or the characters given. */
61
+ trim(characters?: string): Stringable;
62
+ ucfirst(): Stringable;
63
+ upper(): Stringable;
64
+ value(): string;
65
+ }
3
66
 
4
67
  declare const Str: {
68
+ /** Laravel's Str::of(): the value as a Stringable, for chaining: Str.of(title).trim().slug(). */
69
+ of: (value?: unknown) => Stringable;
5
70
  ucfirst: (v: string) => string;
6
71
  lcfirst: (v: string) => string;
7
72
  studly: (v: string) => string;
@@ -9,11 +74,31 @@ declare const Str: {
9
74
  snake: (v: string, delimiter?: string) => string;
10
75
  kebab: (v: string) => string;
11
76
  title: (v: string) => string;
12
- slug: (v: string, separator?: string) => string;
77
+ /** Laravel's Str::ascii(): the value in plain ASCII ('Café' → 'Cafe', 'Ελληνικά' → 'Ellinika'), as for English. */
78
+ ascii: (v: string) => string;
79
+ /**
80
+ * Laravel's Str::slug(): transliterated to ASCII first (unless `language` is null), '@' read as 'at', then lower-cased
81
+ * letters and digits joined by the separator: 'Café crème' → 'cafe-creme'. What has no ASCII form is dropped.
82
+ */
83
+ slug: (title: string, separator?: string, language?: "en" | null, dictionary?: Readonly<Record<string, string>>) => string;
13
84
  plural: (v: string, count?: number) => string;
14
85
  singular: (v: string) => string;
15
86
  random: (length?: number) => string;
16
87
  uuid: () => `${string}-${string}-${string}-${string}-${string}`;
88
+ /**
89
+ * A version 7 UUID (RFC 9562): the time in milliseconds first, so ids from later milliseconds sort after earlier ones
90
+ * (within one millisecond the order is random). Throws a TypeError for a time before 1970, after 10889 or invalid.
91
+ */
92
+ uuid7: (time?: Date) => string;
93
+ /**
94
+ * A ULID: 26 upper-case Crockford characters, ten for the time in milliseconds and sixteen random, so ids from later
95
+ * milliseconds sort after earlier ones. Throws a TypeError for a time before 1970, after 10889 or invalid.
96
+ */
97
+ ulid: (time?: Date) => string;
98
+ /** Laravel's Str::isUuid(): five groups of hex digits, any version. */
99
+ isUuid: (value: unknown) => value is string;
100
+ /** Laravel's Str::isUlid(): 26 Crockford characters in either case, the first at most 7. */
101
+ isUlid: (value: unknown) => value is string;
17
102
  /** Wildcard match: `*` matches anything; everything else is literal. */
18
103
  is: (pattern: string, value: string) => boolean;
19
104
  startsWith: (v: string, needles: string | string[]) => boolean;
@@ -85,4 +170,68 @@ declare function tap<T>(target: T, callback: (target: T) => void): T;
85
170
  /** Calls fn up to `times` times (attempt numbers are 1-based). Rethrows the last error, or the first one `when` rejects. */
86
171
  declare function retry<T>(times: number, fn: (attempt: number) => T | Promise<T>, sleepMs?: number | ((attempt: number) => number), when?: (error: unknown) => boolean): Promise<T>;
87
172
 
88
- export { Arr, ClassRegistry, type Facade, type FacadeStatics, ServiceProvider, Str, app, config, facade, now, retry, tap, value };
173
+ /**
174
+ * Laravel's __(): the line for `key` with `:placeholders` filled (`:name`, `:Name` capitalized, `:NAME` upper-cased),
175
+ * longest placeholder first. A key with no line comes back as is, so a sentence can be its own key:
176
+ * __('auth.failed'), __('auth.throttle', { seconds: 30 }), __('A reset link will be sent if the account exists.').
177
+ */
178
+ declare function __(key: string, replace?: Record<string, string | number>): string;
179
+
180
+ /**
181
+ * What a file's bytes show it to be, read from its leading bytes the way PHP's finfo reads them for Laravel (the file
182
+ * validation rules, and the extension a stored upload gets). The client's file name and MIME type are never consulted.
183
+ */
184
+ interface DetectedType {
185
+ /** 'image/png', 'text/plain', …; 'application/octet-stream' when no format matches, 'application/x-empty' for no bytes. */
186
+ readonly mime: string;
187
+ /** The extensions that name the type, the usual one first. Empty when the bytes match no format. */
188
+ readonly extensions: readonly string[];
189
+ }
190
+ declare const JPEG: DetectedType;
191
+ declare const PNG: DetectedType;
192
+ declare const GIF: DetectedType;
193
+ declare const WEBP: DetectedType;
194
+ declare const AVIF: DetectedType;
195
+ declare const BMP: DetectedType;
196
+ declare const SVG: DetectedType;
197
+ declare const PDF: DetectedType;
198
+ declare const HTML: DetectedType;
199
+ declare const XML: DetectedType;
200
+ declare const TEXT: DetectedType;
201
+ declare const UNKNOWN: DetectedType;
202
+ declare const EMPTY: DetectedType;
203
+ /** The raster formats the image rule accepts: Laravel 12's jpg, jpeg, png, gif, bmp and webp, plus AVIF. */
204
+ declare const RASTER_IMAGES: ReadonlySet<string>;
205
+ /** Every format recognised by its bytes other than plain text. */
206
+ declare const BINARY_AND_MARKUP_TYPES: readonly DetectedType[];
207
+ /**
208
+ * How much of a file is read to tell its type: the window checked for binary bytes (libmagic reads its first megabyte
209
+ * too). Uploads read this much to be named, so naming and validation see the same bytes.
210
+ */
211
+ declare const SNIFF_BYTES: number;
212
+ /** The type the bytes show. */
213
+ declare function detectFileType(bytes: Uint8Array): DetectedType;
214
+
215
+ declare const fileType_AVIF: typeof AVIF;
216
+ declare const fileType_BINARY_AND_MARKUP_TYPES: typeof BINARY_AND_MARKUP_TYPES;
217
+ declare const fileType_BMP: typeof BMP;
218
+ type fileType_DetectedType = DetectedType;
219
+ declare const fileType_EMPTY: typeof EMPTY;
220
+ declare const fileType_GIF: typeof GIF;
221
+ declare const fileType_HTML: typeof HTML;
222
+ declare const fileType_JPEG: typeof JPEG;
223
+ declare const fileType_PDF: typeof PDF;
224
+ declare const fileType_PNG: typeof PNG;
225
+ declare const fileType_RASTER_IMAGES: typeof RASTER_IMAGES;
226
+ declare const fileType_SNIFF_BYTES: typeof SNIFF_BYTES;
227
+ declare const fileType_SVG: typeof SVG;
228
+ declare const fileType_TEXT: typeof TEXT;
229
+ declare const fileType_UNKNOWN: typeof UNKNOWN;
230
+ declare const fileType_WEBP: typeof WEBP;
231
+ declare const fileType_XML: typeof XML;
232
+ declare const fileType_detectFileType: typeof detectFileType;
233
+ declare namespace fileType {
234
+ export { fileType_AVIF as AVIF, fileType_BINARY_AND_MARKUP_TYPES as BINARY_AND_MARKUP_TYPES, fileType_BMP as BMP, type fileType_DetectedType as DetectedType, fileType_EMPTY as EMPTY, fileType_GIF as GIF, fileType_HTML as HTML, fileType_JPEG as JPEG, fileType_PDF as PDF, fileType_PNG as PNG, fileType_RASTER_IMAGES as RASTER_IMAGES, fileType_SNIFF_BYTES as SNIFF_BYTES, fileType_SVG as SVG, fileType_TEXT as TEXT, fileType_UNKNOWN as UNKNOWN, fileType_WEBP as WEBP, fileType_XML as XML, fileType_detectFileType as detectFileType };
235
+ }
236
+
237
+ export { Arr, ClassRegistry, type Facade, type FacadeStatics, fileType as FileType, ServiceProvider, Str, Stringable, __, app, config, facade, now, retry, tap, value };