Skip to content

Commit

Permalink
docs: "what is this?", "when should i use this?", api, types
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Dec 15, 2022
1 parent 2021e44 commit 368a3c8
Show file tree
Hide file tree
Showing 16 changed files with 512 additions and 54 deletions.
475 changes: 455 additions & 20 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/interfaces/pathe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface Pathe extends PlatformPath {
*
* @param {string} path - Path to evaluate
* @param {Nullable<string>} [ext] - Default file extension
* @param {string[]} [ignore] - File extensions to ignore if present
* @param {string[]} [ignore] - File extensions to ignore if found
* @return {string} `path` unmodified or with `ext` appended
* @throws {TypeError} If `path` is not a string or `ext` is not a string
*/
Expand Down
17 changes: 9 additions & 8 deletions src/interfaces/platform-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface PlatformPath {
/**
* Path segment separator.
*
* **Note**: Also known as "directory separator".
* Also known as a "directory separator".
*
* @readonly
*/
Expand Down Expand Up @@ -71,10 +71,10 @@ interface PlatformPath {
dirname(path: string): string

/**
* Returns the extension of the given `path`, from the last occurrence of the
* `.` (dot) character to end of the string in the last portion of the path.
* Returns the extension of a `path`, from the last occurrence of the `.`
* (dot) character to end of the string in the last portion of the path.
*
* If there is no `.` in the last portion of the path, or if there are no `.`
* If there is no `.` in the last portion of `path`, or if there are no `.`
* characters other than the first character of the path's [`basename`][1], an
* empty string will be returned.
*
Expand All @@ -87,7 +87,8 @@ interface PlatformPath {
extname(path: string): EmptyString | Ext

/**
* Returns a path string from an object - the opposite of [`parse()`][1].
* Returns a path string from an object &mdash; the opposite of
* [`parse()`][1].
*
* When adding properties to `pathObject`, there are combinations where one
* property has priority over another:
Expand Down Expand Up @@ -130,7 +131,7 @@ interface PlatformPath {
*
* [1]: {@link ../lib/sep.ts}
*
* @param {string[]} paths - A sequence of path segments
* @param {string[]} paths - Path segment sequence
* @return {string} Path segment sequence, `paths`, as one path
* @throws {TypeError} If any segment in `paths` is not a string
*/
Expand Down Expand Up @@ -213,7 +214,7 @@ interface PlatformPath {
*
* [1]: {@link ../lib/sep.ts}
*
* @param {string[]} paths - A sequence of path segments
* @param {string[]} paths - Path segment sequence
* @return {string} Path segment sequence, `paths`, as absolute path
* @throws {TypeError} If any segment in `paths` is not a string
*/
Expand All @@ -226,7 +227,7 @@ interface PlatformPath {
* returned without modifications.
*
* [1]: https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#namespaces
* [2]: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
* [2]: https://learn.microsoft.com/windows/win32/fileio/naming-a-file#naming-conventions
* [3]: https://learn.microsoft.com/dotnet/standard/io/file-path-formats#unc-paths
*
* @param {string} path - Path to evaluate
Expand Down
6 changes: 3 additions & 3 deletions src/lib/extname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import type { Ext } from '#src/types'
import type { EmptyString } from '@flex-development/tutils'

/**
* Returns the extension of the given `path`, from the last occurrence of the
* `.` (dot) character to end of the string in the last portion of the path.
* Returns the extension of a `path`, from the last occurrence of the `.` (dot)
* character to end of the string in the last portion of the path.
*
* If there is no `.` in the last portion of the path, or if there are no `.`
* If there is no `.` in the last portion of `path`, or if there are no `.`
* characters other than the first character of the path's [`basename`][1], an
* empty string will be returned.
*
Expand Down
2 changes: 1 addition & 1 deletion src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import formatExt from '#src/utils/format-ext'
import sep from './sep'

/**
* Returns a path string from an object - the opposite of [`parse()`][1].
* Returns a path string from an object &mdash; the opposite of [`parse`][1].
*
* When adding properties to `pathObject`, there are combinations where one
* property has priority over another:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import sep from './sep'
*
* [1]: {@link ./sep.ts}
*
* @param {string[]} paths - A sequence of path segments
* @param {string[]} paths - Path segment sequence
* @return {string} Path segment sequence, `paths`, as one path
* @throws {TypeError} If any segment in `paths` is not a string
*/
Expand Down
10 changes: 5 additions & 5 deletions src/lib/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import sep from './sep'

/**
* Returns an object whose properties represent significant elements of the
* given `path`. Trailing directory [separators][1] are ignored.
* given `path`. Trailing [directory separators][1] are ignored.
*
* **Note**: Unlike in Node.js, `pathe.parse(path).dir === pathe.dirname(path)`
* when `path` is a non-empty string. See [`nodejs/node#18655`][3] for details.
* **Note**: `parse(path).dir === dirname(path)` when `path` is a non-empty
* string. This is stark contrast to `node:path`. See [`nodejs/node#18655`][2]
* for details.
*
* [1]: {@link ./sep.ts}
* [2]: {@link ./dirname.ts}
* [3]: https://github.com/nodejs/node/issues/18655
* [2]: https://github.com/nodejs/node/issues/18655
*
* @param {string} path - Path to evaluate
* @return {ParsedPath} Object representing significant elements of `path`
Expand Down
2 changes: 1 addition & 1 deletion src/lib/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import sep from './sep'
*
* [1]: {@link ./sep.ts}
*
* @param {string[]} paths - A sequence of path segments
* @param {string[]} paths - Path segment sequence
* @return {string} Path segment sequence, `paths`, as absolute path
* @throws {TypeError} If any segment in `paths` is not a string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Sep } from '#src/types'
/**
* Path segment separator.
*
* **Note**: Also known as "directory separator".
* Also known as a "directory separator".
*
* @const {Sep} sep
*/
Expand Down
4 changes: 2 additions & 2 deletions src/lib/to-namespaced-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import sep from './sep'
* If `path` is not a [drive path][2] or [UNC path][3], `path` will be returned
* without modifications.
*
* [1]: https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#namespaces
* [2]: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
* [1]: https://docs.microsoft.com/windows/desktop/FileIO/naming-a-file#namespaces
* [2]: https://learn.microsoft.com/windows/win32/fileio/naming-a-file#naming-conventions
* [3]: https://learn.microsoft.com/dotnet/standard/io/file-path-formats#unc-paths
*
* @param {string} path - Path to evaluate
Expand Down
5 changes: 3 additions & 2 deletions src/utils/__tests__/default-ext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ describe('unit:utils/defaultExt', () => {
it('should return path with ext appended', () => {
// Arrange
const cases: [...Parameters<typeof testSubject>, string][] = [
['file', 'mjs', undefined, 'file.mjs'],
['file.', '.mjs', undefined, 'file.mjs'],
['file', 'mjs', [], 'file.mjs'],
['file.', '.mjs', [], 'file.mjs'],
['file.d', 'mts', ['.d'], 'file.d.mts'],
['file.min', 'mjs', ['.min'], 'file.min.mjs'],
['file.min', '.mjs', [null, '.min'] as string[], 'file.min.mjs']
]
Expand Down
16 changes: 13 additions & 3 deletions src/utils/__tests__/format-ext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ describe('unit:utils/formatExt', () => {
ext = '.mjs'
})

it('should return empty string if ext is empty string', () => {
expect(testSubject('')).to.equal('')
it('should return empty string if ext is empty', () => {
// Arrange
const cases: [...Parameters<typeof testSubject>, string][] = [
['', ''],
[' ', ''],
[undefined, '']
]

// Act + Expect
cases.forEach(([ext, expected]) => {
expect(testSubject(ext)).to.equal(expected)
})
})

it('should return ext without modifications if ext starts with dot', () => {
it('should return ext if ext starts with dot character', () => {
expect(testSubject(ext)).to.equal(ext)
})

Expand Down
4 changes: 2 additions & 2 deletions src/utils/add-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import formatExt from './format-ext'
* @example
* addExt('file', 'mjs') // 'file.mjs'
* @example
* addExt('file.min', '.mjs') // 'file.min.mjs'
* addExt('file', '.mjs') // 'file.mjs'
* @example
* addExt('file.min.mjs', '.mjs') // 'file.min.mjs'
* addExt('file.d.mts', '.mts') // 'file.d.mts'
*
* @param {string} path - Path to evaluate
* @param {Nullable<string>} [ext] - File extension to add
Expand Down
4 changes: 2 additions & 2 deletions src/utils/default-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import formatExt from './format-ext'
* @example
* defaultExt('file.mjs', '.mjs') // 'file.mjs'
* @example
* defaultExt('file.min', '.mjs', ['.min']) // 'file.min.mjs'
* defaultExt('file.d', '.mts', ['.d']) // 'file.d.mts'
*
* @param {string} path - Path to evaluate
* @param {Nullable<string>} [ext] - Default file extension
* @param {string[]} [ignore] - File extensions to ignore if present
* @param {string[]} [ignore] - File extensions to ignore if found
* @return {string} `path` unmodified or with `ext` appended
* @throws {TypeError} If `path` is not a string or `ext` is not a string
*/
Expand Down
11 changes: 11 additions & 0 deletions src/utils/format-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import type { EmptyString } from '@flex-development/tutils'
*
* Does nothing if a file extension isn't provided.
*
* @example
* formatExt() // ''
* @example
* formatExt('') // ''
* @example
* formatExt('.ts') // '.ts'
* @example
* formatExt('mjs') // '.mjs'
* @example
* formatExt('d.mts') // '.d.mts'
*
* @param {string} [ext=''] - File extension to format
* @return {EmptyString | Ext} Formatted file extension or empty string
*/
Expand Down
4 changes: 2 additions & 2 deletions src/utils/remove-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import formatExt from './format-ext'
* @example
* removeExt('file.mjs', 'mjs') // 'file'
* @example
* removeExt('file.mjs', '.ts') // 'file.mjs'
* removeExt('file.mjs', '.mjs') // 'file'
* @example
* removeExt('file.min.mjs', '.mjs') // 'file.min'
* removeExt('file.d.mts', '.mjs') // 'file.d.mts'
*
* @param {string} path - Path to evaluate
* @param {Nullable<string>} [ext] - File extension to removed
Expand Down

0 comments on commit 368a3c8

Please sign in to comment.