@byjohann/utils
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -0,1 +1,2 @@ | ||
type CSVRow<T extends string = string> = Record<T, string>; | ||
/** | ||
@@ -9,3 +10,3 @@ * Converts an array of objects to a comma-separated values (CSV) string | ||
/** @default true */ | ||
includeHeaders?: boolean; | ||
addHeader?: boolean; | ||
/** @default false */ | ||
@@ -15,2 +16,9 @@ quoteAll?: boolean; | ||
/** | ||
* Parses a comma-separated values (CSV) string into an array of objects. | ||
* | ||
* @remarks | ||
* The first row of the CSV string is used as the header row. | ||
*/ | ||
declare function parseCSV<Header extends string>(csv: string): CSVRow<Header>[]; | ||
/** | ||
* Escapes a value for a CSV string. | ||
@@ -23,2 +31,2 @@ * | ||
export { createCSV, escapeCSVValue }; | ||
export { type CSVRow, createCSV, escapeCSVValue, parseCSV }; |
export { MaybeArray, toArray } from './array.js'; | ||
export { createCSV, escapeCSVValue } from './csv.js'; | ||
export { CSVRow, createCSV, escapeCSVValue, parseCSV } from './csv.js'; | ||
export { tryParseJSON } from './json.js'; | ||
export { interopDefault } from './module.js'; | ||
export { deepApply, objectEntries, objectKeys } from './object.js'; | ||
export { getPathname, joinURL, withLeadingSlash, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash } from './path.js'; | ||
export { QueryObject, QueryValue, getPathname, joinURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash } from './path.js'; | ||
export { generateRandomId, template, unindent } from './string.js'; | ||
export { AutocompletableString, LooseAutocomplete, UnifyIntersection } from './types.js'; |
@@ -0,1 +1,3 @@ | ||
type QueryValue = string | number | boolean | QueryValue[] | Record<string, any> | null | undefined; | ||
type QueryObject = Record<string, QueryValue | QueryValue[]>; | ||
/** | ||
@@ -22,2 +24,6 @@ * Removes the leading slash from the given path if it has one. | ||
/** | ||
* Adds the base path to the input path, if it is not already present. | ||
*/ | ||
declare function withBase(input?: string, base?: string): string; | ||
/** | ||
* Removes the base path from the input path, if it is present. | ||
@@ -30,3 +36,7 @@ */ | ||
declare function getPathname(path?: string): string; | ||
/** | ||
* Returns the URL with the given query parameters. If a query parameter is undefined, it is omitted. | ||
*/ | ||
declare function withQuery(input: string, query?: QueryObject): string; | ||
export { getPathname, joinURL, withLeadingSlash, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash }; | ||
export { type QueryObject, type QueryValue, getPathname, joinURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash }; |
@@ -14,3 +14,3 @@ /** | ||
* | ||
* @remarks Ported from nanoid. | ||
* @remarks Ported from `nanoid`. | ||
* @see https://github.com/ai/nanoid | ||
@@ -17,0 +17,0 @@ */ |
{ | ||
"name": "@byjohann/utils", | ||
"type": "module", | ||
"version": "0.6.1", | ||
"packageManager": "pnpm@9.7.1", | ||
"version": "0.7.0", | ||
"packageManager": "pnpm@9.11.0", | ||
"description": "A collection of utilities for my projects", | ||
@@ -68,2 +68,3 @@ "author": "Johann Schopplich <hello@johannschopplich.com>", | ||
"lint:fix": "eslint . --fix", | ||
"test": "vitest", | ||
"test:types": "tsc --noEmit", | ||
@@ -73,9 +74,10 @@ "release": "bumpp" | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^2.25.1", | ||
"@types/node": "^20.14.15", | ||
"bumpp": "^9.5.1", | ||
"eslint": "^9.9.0", | ||
"@antfu/eslint-config": "^3.7.1", | ||
"@types/node": "^20.16.7", | ||
"bumpp": "^9.5.2", | ||
"eslint": "^9.11.1", | ||
"typescript": "^5.5.4", | ||
"unbuild": "^3.0.0-rc.7" | ||
"unbuild": "^3.0.0-rc.7", | ||
"vitest": "^2.1.1" | ||
} | ||
} |
@@ -55,2 +55,15 @@ # @byjohann/utils | ||
#### `parseCSV` | ||
Parses a comma-separated values (CSV) string into an array of objects. | ||
> [!NOTE] | ||
> The first row of the CSV string is used as the header row. | ||
```ts | ||
type CSVRow<T extends string = string> = Record<T, string> | ||
declare function parseCSV<Header extends string>(csv: string): CSVRow<Header>[] | ||
``` | ||
#### `escapeCSVValue` | ||
@@ -105,3 +118,5 @@ | ||
const mod = await interopDefault(import('./module.js')) | ||
async function loadModule() { | ||
const mod = await interopDefault(import('./module.js')) | ||
} | ||
``` | ||
@@ -177,2 +192,10 @@ | ||
#### `withBase` | ||
Adds the base path to the input path, if it is not already present. | ||
```ts | ||
declare function withBase(input?: string, base?: string): string | ||
``` | ||
#### `withoutBase` | ||
@@ -194,2 +217,24 @@ | ||
#### `withQuery` | ||
Returns the URL with the given query parameters. If a query parameter is undefined, it is omitted. | ||
```ts | ||
declare function withQuery(input: string, query?: QueryObject): string | ||
``` | ||
**Example:** | ||
```ts | ||
import { withQuery } from '@byjohann/utils' | ||
const url = withQuery('https://example.com', { | ||
foo: 'bar', | ||
// This key is omitted | ||
baz: undefined, | ||
// Object values are stringified | ||
baz: { qux: 'quux' } | ||
}) | ||
``` | ||
### String | ||
@@ -218,3 +263,3 @@ | ||
Generates a random string. | ||
Generates a random string. The function is ported from [`nanoid`](https://github.com/ai/nanoid). You can specify the size of the string and the dictionary of characters to use. | ||
@@ -221,0 +266,0 @@ ```ts |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28868
404
276
7