Skip to content

Commit

Permalink
build(deps): bump @flex-development/tutils from 6.0.0-alpha.10 to 6.0…
Browse files Browse the repository at this point in the history
….0-alpha.12

Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Jul 29, 2023
1 parent 68ce28c commit 34edb7d
Show file tree
Hide file tree
Showing 35 changed files with 247 additions and 177 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const config = {
allowedNames: ['self']
}
],
'@typescript-eslint/no-throw-literal': 2,
'@typescript-eslint/no-throw-literal': 0,
'@typescript-eslint/no-type-alias': 0,
'@typescript-eslint/no-unnecessary-boolean-literal-compare': [
2,
Expand Down Expand Up @@ -581,6 +581,7 @@ const config = {
'no-return-await': 0,
'no-shadow': 0,
'no-sparse-arrays': 0,
'no-throw-literal': 0,
'no-unused-expressions': 0,
'no-unused-vars': 0,
'no-use-before-define': 0,
Expand Down Expand Up @@ -661,7 +662,7 @@ const config = {
terms: ['@fixme', '@todo']
}
],
'unicorn/explicit-length-check': 2,
'unicorn/explicit-length-check': 0,
'unicorn/filename-case': [
2,
{
Expand Down Expand Up @@ -858,7 +859,6 @@ const config = {
'promise/valid-params': 0,
'unicorn/consistent-destructuring': 0,
'unicorn/error-message': 0,
'unicorn/explicit-length-check': 0,
'unicorn/no-array-for-each': 0,
'unicorn/no-hex-escape': 0,
'unicorn/no-useless-undefined': 0,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
"typecheck:watch": "vitest typecheck"
},
"dependencies": {
"@flex-development/errnode": "1.5.0",
"@flex-development/tutils": "6.0.0-alpha.10"
"@flex-development/errnode": "2.0.0",
"@flex-development/tutils": "6.0.0-alpha.12"
},
"devDependencies": {
"@commitlint/cli": "17.6.3",
Expand Down Expand Up @@ -164,7 +164,7 @@
},
"resolutions": {
"@ardatan/sync-fetch": "larsgw/sync-fetch#head=worker_threads",
"@flex-development/tutils": "6.0.0-alpha.10"
"@flex-development/tutils": "6.0.0-alpha.12"
},
"engines": {
"node": ">=16.20.0",
Expand Down
10 changes: 5 additions & 5 deletions src/interfaces/__tests__/parsed-path.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import type TestSubject from '../parsed-path'

describe('unit-d:interfaces/ParsedPath', () => {
it('should match [base: string]', () => {
expectTypeOf<TestSubject>().toHaveProperty('base').toBeString()
expectTypeOf<TestSubject>().toHaveProperty('base').toEqualTypeOf<string>()
})

it('should match [dir: string]', () => {
expectTypeOf<TestSubject>().toHaveProperty('dir').toBeString()
expectTypeOf<TestSubject>().toHaveProperty('dir').toEqualTypeOf<string>()
})

it('should match [ext: string]', () => {
expectTypeOf<TestSubject>().toHaveProperty('ext').toBeString()
expectTypeOf<TestSubject>().toHaveProperty('ext').toEqualTypeOf<string>()
})

it('should match [name: string]', () => {
expectTypeOf<TestSubject>().toHaveProperty('name').toBeString()
expectTypeOf<TestSubject>().toHaveProperty('name').toEqualTypeOf<string>()
})

it('should match [root: string]', () => {
expectTypeOf<TestSubject>().toHaveProperty('root').toBeString()
expectTypeOf<TestSubject>().toHaveProperty('root').toEqualTypeOf<string>()
})
})
4 changes: 2 additions & 2 deletions src/interfaces/__tests__/path-object.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* @module pathe/interfaces/tests/unit-d/PathObject
*/

import type { KeysRequired } from '@flex-development/tutils'
import type { RequiredKeys } from '@flex-development/tutils'
import type TestSubject from '../path-object'

describe('unit-d:interfaces/PathObject', () => {
it('should allow empty object', () => {
expectTypeOf<KeysRequired<TestSubject>>().toBeNever()
expectTypeOf<RequiredKeys<TestSubject>>().toBeNever()
})

it('should match [base?: string]', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/parsed-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module pathe/interfaces/ParsedPath
*/

import type { ExactOptionalPropertyTypes } from '@flex-development/tutils'
import type { Shake } from '@flex-development/tutils'
import type PathObject from './path-object'

/**
Expand All @@ -17,8 +17,8 @@ import type PathObject from './path-object'
*
* @see [`PathObject`][3]
*
* @extends {ExactOptionalPropertyTypes<Required<PathObject>>}
* @extends {Required<Shake<PathObject>>}
*/
interface ParsedPath extends ExactOptionalPropertyTypes<Required<PathObject>> {}
interface ParsedPath extends Required<Shake<PathObject>> {}

export type { ParsedPath as default }
12 changes: 7 additions & 5 deletions src/interfaces/path-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @module pathe/interfaces/PathObject
*/

import type { Optional } from '@flex-development/tutils'

/**
* Object representing a path.
*/
Expand All @@ -15,7 +17,7 @@ interface PathObject {
* @example
* 'index.html'
*/
base?: string | undefined
base?: Optional<string>

/**
* Directory name or full directory path.
Expand All @@ -27,7 +29,7 @@ interface PathObject {
* @example
* '/home/user/dir'
*/
dir?: string | undefined
dir?: Optional<string>

/**
* File extension (if any).
Expand All @@ -39,7 +41,7 @@ interface PathObject {
* @example
* 'ts'
*/
ext?: string | undefined
ext?: Optional<string>

/**
* File name without extension (if any).
Expand All @@ -49,7 +51,7 @@ interface PathObject {
* @example
* 'index'
*/
name?: string | undefined
name?: Optional<string>

/**
* Root of path.
Expand All @@ -61,7 +63,7 @@ interface PathObject {
* @example
* 'c:\\'
*/
root?: string | undefined
root?: Optional<string>
}

export type { PathObject as default }
18 changes: 9 additions & 9 deletions src/interfaces/pathe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Ext } from '#src/types'
import type { EmptyString, Nullable } from '@flex-development/tutils'
import type { EmptyString, Nilable } from '@flex-development/tutils'
import type PlatformPath from './platform-path'

/**
Expand All @@ -20,11 +20,11 @@ interface Pathe extends PlatformPath {
* Does nothing if a file extension is not provided.
*
* @param {string} path - Path to evaluate
* @param {Nullable<string>} [ext] - File extension to add
* @param {Nilable<string>} [ext] - File extension to add
* @return {string} `path` unmodified or with `ext` appended
* @throws {TypeError} If `path` is not a string or `ext` is not a string
*/
addExt(path: string, ext?: Nullable<string>): string
addExt(path: string, ext?: Nilable<string>): string

/**
* Changes the file extension of the given `path`.
Expand All @@ -33,11 +33,11 @@ interface Pathe extends PlatformPath {
* an empty string, however, `path`'s file extension will be removed.
*
* @param {string} path - Path to evaluate
* @param {Nullable<string>} [ext] - New file extension
* @param {Nilable<string>} [ext] - New file extension
* @return {string} `path` unmodified or with changed file extension
* @throws {TypeError} If `path` is not a string or `ext` is not a string
*/
changeExt(path: string, ext?: Nullable<string>): string
changeExt(path: string, ext?: Nilable<string>): string

/**
* Appends a file extension to the given `path` if and only if the path does
Expand All @@ -47,12 +47,12 @@ interface Pathe extends PlatformPath {
* Does nothing if a file extension isn't provided.
*
* @param {string} path - Path to evaluate
* @param {Nullable<string>} [ext] - Default file extension
* @param {Nilable<string>} [ext] - Default file extension
* @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
*/
defaultExt(path: string, ext?: Nullable<string>, ignore?: string[]): string
defaultExt(path: string, ext?: Nilable<string>, ignore?: string[]): string

/**
* Formats a file extension.
Expand All @@ -75,11 +75,11 @@ interface Pathe extends PlatformPath {
* a file extension isn't provided.
*
* @param {string} path - Path to evaluate
* @param {Nullable<string>} [ext] - File extension to removed
* @param {Nilable<string>} [ext] - File extension to removed
* @return {string} `path` unmodified or with `ext` removed
* @throws {TypeError} If `path` is not a string or `ext` is not a string
*/
removeExt(path: string, ext?: Nullable<string>): string
removeExt(path: string, ext?: Nilable<string>): string
}

export type { Pathe as default }
13 changes: 5 additions & 8 deletions src/internal/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
* @module pathe/internal/constants
*/

/**
* Dot character.
*
* @const {string} DOT
*/
const DOT: string = '.'

/**
* Drive path regex.
*
Expand All @@ -19,6 +12,8 @@ const DOT: string = '.'
*
* @see https://regex101.com/r/FsoDwJ
*
* @internal
*
* @const {RegExp} DRIVE_PATH_REGEX
*/
const DRIVE_PATH_REGEX: RegExp = /^(?<drive>(?<letter>[a-z]):(?:\/|\\{2})?)/i
Expand All @@ -29,9 +24,11 @@ const DRIVE_PATH_REGEX: RegExp = /^(?<drive>(?<letter>[a-z]):(?:\/|\\{2})?)/i
* @see https://regex101.com/r/3P8YKp
* @see https://learn.microsoft.com/dotnet/standard/io/file-path-formats#unc-paths
*
* @internal
*
* @const {RegExp} UNC_PATH_REGEX
*/
const UNC_PATH_REGEX: RegExp =
/^(?<volume>[/\\]{2,}(?<host>[^/\\]+)[/\\]+(?<share>[^/\\]+)[/\\]*)(?:(?<dir>.+?)[/\\]*(?<file>[^/\\]+\..[^/\\]+)?[/\\]*(?=[/\\]*\n?$))?/

export { DOT, DRIVE_PATH_REGEX, UNC_PATH_REGEX }
export { DRIVE_PATH_REGEX, UNC_PATH_REGEX }
2 changes: 2 additions & 0 deletions src/internal/ensure-posix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import validateString from './validate-string'
* @see https://nodejs.org/api/path.html#pathdelimiter
* @see https://nodejs.org/api/path.html#pathsep
*
* @internal
*
* @param {string} [path=''] - Path to ensure
* @return {string} POSIX-compliant `path`
* @throws {TypeError} If `path` is not a string
Expand Down
2 changes: 2 additions & 0 deletions src/internal/is-drive-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import validateString from './validate-string'
* @example
* isDrivePath('myfile.html') // false
*
* @internal
*
* @param {string} path - Path to evaluate
* @return {boolean} `true` if path starts with [drive letter][1]
* @throws {TypeError} If `path` is not a string
Expand Down
4 changes: 3 additions & 1 deletion src/internal/is-sep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import type { Sep } from '#src/types'
*
* @see [`sep`][1]
*
* @internal
*
* @param {unknown} value - Possible path separator
* @return {value is Sep} `true` if `str` is path separator
*/
const isSep = (value: unknown): value is Sep => value === sep
const isSep = (value: unknown): value is Sep => sep === value

export default isSep
2 changes: 2 additions & 0 deletions src/internal/is-unc-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import validateString from './validate-string'
*
* @see https://learn.microsoft.com/dotnet/standard/io/file-path-formats#unc-paths
*
* @internal
*
* @param {string} path - Path to evaluate
* @param {boolean} [exact=true] - Check for exactly two leading separators
* @return {boolean} `true` if path is UNC path
Expand Down
24 changes: 17 additions & 7 deletions src/internal/normalize-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@

import isAbsolute from '#src/lib/is-absolute'
import sep from '#src/lib/sep'
import { DOT } from './constants'
import {
DOT,
at,
ifelse,
includes,
isEmptyString,
trim,
type Optional
} from '@flex-development/tutils'
import ensurePosix from './ensure-posix'
import isSep from './is-sep'
import validateString from './validate-string'
Expand All @@ -22,6 +30,8 @@ import validateString from './validate-string'
*
* [1]: {@link ../lib/sep.ts}
*
* @internal
*
* @param {string} path - Path to normalize
* @param {boolean} [allow_above_root=!isAbsolute(path)] - Normalize past root
* @return {string} Normalized `path`
Expand All @@ -34,20 +44,20 @@ const normalizeString = (
validateString(path, 'path')

// exit early if path is empty string
if (path.trim().length === 0) return path
if (isEmptyString(trim(path))) return path

// ensure path meets posix standards
path = ensurePosix(path)

// exit early if path does not contain dot characters or separators
if (!path.includes(DOT) && !path.includes(sep)) return path
if (!includes(path, DOT) && !includes(path, sep)) return path

/**
* Current character in {@link path} being processed.
*
* @var {string | undefined} char
* @var {Optional<string>} char
*/
let char: string | undefined
let char: Optional<string>

/**
* Total number of `.` (dot) characters in current path segment.
Expand Down Expand Up @@ -80,7 +90,7 @@ const normalizeString = (
// normalize
for (let i = 0; i <= path.length; ++i) {
// set current character if current index is in bounds
if (i < path.length) char = path[i]
if (i < path.length) char = at(path, i)
// exit if trailing separator has been reached
else if (isSep(char)) break
// add trailing separator
Expand Down Expand Up @@ -133,7 +143,7 @@ const normalizeString = (

// resolve past root
if (allow_above_root) {
res += `${!res ? '' : sep}${DOT.repeat(2)}`
res += `${ifelse(!res, '', sep)}${DOT.repeat(2)}`
seglen = 2
}
} else {
Expand Down
Loading

0 comments on commit 34edb7d

Please sign in to comment.