@constructive-io/upload-names 2.3.3

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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
4
+ Copyright (c) 2025 Constructive <developers@constructive.io>
5
+ Copyright (c) 2020-present, Interweb, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # @constructive-io/upload-names
2
+
3
+ <p align="center" width="100%">
4
+ <img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5
+ </p>
6
+
7
+ <p align="center" width="100%">
8
+ <a href="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml">
9
+ <img height="20" src="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml/badge.svg" />
10
+ </a>
11
+ <a href="https://github.com/constructive-io/constructive/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
12
+ <a href="https://www.npmjs.com/package/@constructive-io/upload-names"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/constructive?filename=packages%2Fupload-names%2Fpackage.json"/></a>
13
+ </p>
14
+
15
+ ```sh
16
+ npm install @constructive-io/upload-names
17
+ ```
18
+
19
+ naming files for URLs
20
+
21
+ ```js
22
+ const results = await getName(filename, options);
23
+ ```
24
+
25
+ ## options
26
+
27
+ ### english (bool)
28
+
29
+ if you want super URL-friendly names, use
30
+
31
+ ```
32
+ english: true
33
+ ```
34
+
35
+ #### notes
36
+
37
+ * `english=true`, can end up stripping the entire string if it's not a good input, and it will throw an error.
38
+
39
+ * `english=false` allows languages like chinese and russian, however, they get converted into super ugly URLs because of web standards.
40
+
41
+ ### lower (bool)
42
+
43
+ lowercase is ideal for URLs, but not necessary
44
+
45
+ ```
46
+ lower: true
47
+ ```
48
+
49
+ ### delimeter
50
+
51
+ defaults to `-`
52
+
53
+ ---
54
+
55
+ ## Education and Tutorials
56
+
57
+ 1. 🚀 [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
58
+ Get started with modular databases in minutes. Install prerequisites and deploy your first module.
59
+
60
+ 2. 📦 [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
61
+ Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
62
+
63
+ 3. ✏️ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
64
+ Master the workflow for adding, organizing, and managing database changes with pgpm.
65
+
66
+ 4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
67
+ Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
68
+
69
+ 5. ⚡ [Supabase Testing](https://constructive.io/learn/supabase)
70
+ Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
71
+
72
+ 6. 💧 [Drizzle ORM Testing](https://constructive.io/learn/drizzle-testing)
73
+ Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
74
+
75
+ 7. 🔧 [Troubleshooting](https://constructive.io/learn/troubleshooting)
76
+ Common issues and solutions for pgpm, PostgreSQL, and testing.
77
+
78
+ ## Related Constructive Tooling
79
+
80
+ ### 🧪 Testing
81
+
82
+ * [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
83
+ * [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
84
+ * [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
85
+ * [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
86
+
87
+ ### 🧠 Parsing & AST
88
+
89
+ * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
90
+ * [libpg-query-node](https://www.npmjs.com/package/libpg-query): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
91
+ * [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
92
+ * [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
93
+ * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
94
+ * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
95
+ * [pg-ast](https://www.npmjs.com/package/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
96
+
97
+ ### 🚀 API & Dev Tools
98
+
99
+ * [@constructive-io/graphql-server](https://github.com/constructive-io/constructive/tree/main/graphql/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
100
+ * [@constructive-io/graphql-explorer](https://github.com/constructive-io/constructive/tree/main/graphql/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
101
+
102
+ ### 🔁 Streaming & Uploads
103
+
104
+ * [etag-hash](https://github.com/constructive-io/constructive/tree/main/streaming/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
105
+ * [etag-stream](https://github.com/constructive-io/constructive/tree/main/streaming/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
106
+ * [uuid-hash](https://github.com/constructive-io/constructive/tree/main/streaming/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
107
+ * [uuid-stream](https://github.com/constructive-io/constructive/tree/main/streaming/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
108
+ * [@constructive-io/s3-streamer](https://github.com/constructive-io/constructive/tree/main/streaming/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
109
+ * [@constructive-io/upload-names](https://github.com/constructive-io/constructive/tree/main/streaming/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
110
+
111
+ ### 🧰 CLI & Codegen
112
+
113
+ * [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
114
+ * [@constructive-io/cli](https://github.com/constructive-io/constructive/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing Constructive projects—supports database scaffolding, migrations, seeding, code generation, and automation.
115
+ * [@constructive-io/graphql-codegen](https://github.com/constructive-io/constructive/tree/main/graphql/codegen): **✨ GraphQL code generation** (types, operations, SDK) from schema/endpoint introspection.
116
+ * [@constructive-io/query-builder](https://github.com/constructive-io/constructive/tree/main/packages/query-builder): **🏗️ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure calls—supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries.
117
+ * [@constructive-io/graphql-query](https://github.com/constructive-io/constructive/tree/main/graphql/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
118
+
119
+ ## Credits
120
+
121
+ **🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
122
+
123
+ ## Disclaimer
124
+
125
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
126
+
127
+ No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
package/esm/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import { basename, extname } from 'path';
2
+ import slugify from './slugify';
3
+ export default (filename, { english = true, lower = true, delimeter = '-' } = {}) => {
4
+ // Step 1: Normalize input
5
+ filename = filename.trim().replace(/\.{2,}/g, '.'); // collapse double dots
6
+ const ext = extname(filename);
7
+ const base = basename(filename, ext);
8
+ // Step 2: Normalize base name
9
+ const name = base
10
+ .replace(/\s+/g, delimeter)
11
+ .replace(new RegExp(`${delimeter}{2,}`, 'g'), delimeter)
12
+ .trim();
13
+ // Step 3: Sluggify (ASCII-only if english = true)
14
+ let slug = name;
15
+ if (english) {
16
+ slug = slugify(name);
17
+ if (slug.length === 0 && name.length > 0) {
18
+ // Optionally fallback instead of throwing:
19
+ // return `${crypto.randomUUID()}${ext}`;
20
+ throw new Error(`BAD_FILE_NAME ${name}`);
21
+ }
22
+ }
23
+ const result = english ? `${slug}${slugify(ext)}` : `${name}${ext}`;
24
+ return lower ? result.toLowerCase() : result;
25
+ };
package/esm/slugify.js ADDED
@@ -0,0 +1,9 @@
1
+ export default (text) => {
2
+ text = text.toString().trim();
3
+ text = text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
4
+ return text
5
+ .replace(/\s+/g, '-') // Replace spaces with -
6
+ .replace(/--+/g, '-') // Replace multiple - with single -
7
+ .replace(/^-+/, '') // Trim - from start of text
8
+ .replace(/-+$/, ''); // Trim - from end of text
9
+ };
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ interface Options {
2
+ english?: boolean;
3
+ lower?: boolean;
4
+ delimeter?: string;
5
+ }
6
+ declare const _default: (filename: string, { english, lower, delimeter }?: Options) => string;
7
+ export default _default;
package/index.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = require("path");
7
+ const slugify_1 = __importDefault(require("./slugify"));
8
+ exports.default = (filename, { english = true, lower = true, delimeter = '-' } = {}) => {
9
+ // Step 1: Normalize input
10
+ filename = filename.trim().replace(/\.{2,}/g, '.'); // collapse double dots
11
+ const ext = (0, path_1.extname)(filename);
12
+ const base = (0, path_1.basename)(filename, ext);
13
+ // Step 2: Normalize base name
14
+ const name = base
15
+ .replace(/\s+/g, delimeter)
16
+ .replace(new RegExp(`${delimeter}{2,}`, 'g'), delimeter)
17
+ .trim();
18
+ // Step 3: Sluggify (ASCII-only if english = true)
19
+ let slug = name;
20
+ if (english) {
21
+ slug = (0, slugify_1.default)(name);
22
+ if (slug.length === 0 && name.length > 0) {
23
+ // Optionally fallback instead of throwing:
24
+ // return `${crypto.randomUUID()}${ext}`;
25
+ throw new Error(`BAD_FILE_NAME ${name}`);
26
+ }
27
+ }
28
+ const result = english ? `${slug}${(0, slugify_1.default)(ext)}` : `${name}${ext}`;
29
+ return lower ? result.toLowerCase() : result;
30
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@constructive-io/upload-names",
3
+ "version": "2.3.3",
4
+ "author": "Constructive <developers@constructive.io>",
5
+ "description": "upload names",
6
+ "main": "index.js",
7
+ "module": "esm/index.js",
8
+ "types": "index.d.ts",
9
+ "homepage": "https://github.com/constructive-io/constructive",
10
+ "license": "MIT",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "directory": "dist"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/constructive-io/constructive"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/constructive-io/constructive/issues"
21
+ },
22
+ "scripts": {
23
+ "clean": "makage clean",
24
+ "prepack": "npm run build",
25
+ "build": "makage build",
26
+ "build:dev": "makage build --dev",
27
+ "lint": "eslint . --fix",
28
+ "test": "jest --passWithNoTests",
29
+ "test:watch": "jest --watch"
30
+ },
31
+ "keywords": [],
32
+ "devDependencies": {
33
+ "glob": "^13.0.0",
34
+ "makage": "^0.1.8"
35
+ },
36
+ "gitHead": "22cfe32e994e26a6490e04e28bab26d1e7e6345c"
37
+ }
package/slugify.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const _default: (text: string) => string;
2
+ export default _default;
package/slugify.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (text) => {
4
+ text = text.toString().trim();
5
+ text = text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
6
+ return text
7
+ .replace(/\s+/g, '-') // Replace spaces with -
8
+ .replace(/--+/g, '-') // Replace multiple - with single -
9
+ .replace(/^-+/, '') // Trim - from start of text
10
+ .replace(/-+$/, ''); // Trim - from end of text
11
+ };