Comparing version 0.25.0 to 0.26.0
@@ -7,10 +7,2 @@ export type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; | ||
/** | ||
* The goal of the number literal and bigint literal regular expressions is to: | ||
* | ||
* 1. Ensure definitions form a bijection with the values they represent. | ||
* 2. Attempt to mirror TypeScript's own format for stringification of numeric | ||
* values such that the regex should match a given definition if any only if | ||
* a precise literal type will be inferred (in TS4.8+). | ||
*/ | ||
/** | ||
* Matches a well-formatted numeric expression according to the following rules: | ||
@@ -24,2 +16,9 @@ * 1. Must include an integer portion (i.e. '.321' must be written as '0.321') | ||
export declare const isWellFormedNumber: RegExp["test"]; | ||
/** | ||
* Similar to wellFormedNumber but more permissive in the following ways: | ||
* | ||
* - Allows numbers without an integer portion like ".5" (well-formed equivalent is "0.5") | ||
* - Allows decimals with trailing zeroes like "0.10" (well-formed equivalent is "0.1") | ||
*/ | ||
export declare const numericStringMatcher: RegExp; | ||
export declare const numberLikeMatcher: RegExp; | ||
@@ -26,0 +25,0 @@ /** |
import { throwParseError } from "./errors.js"; | ||
import { anchoredRegex, RegexPatterns } from "./strings.js"; | ||
/** | ||
@@ -10,2 +11,13 @@ * The goal of the number literal and bigint literal regular expressions is to: | ||
*/ | ||
const anchoredNegativeZeroPattern = /^-0\.?0*$/.source; | ||
const positiveIntegerPattern = /[1-9]\d*/.source; | ||
const looseDecimalPattern = /\.\d+/.source; | ||
const strictDecimalPattern = /\.\d*[1-9]/.source; | ||
const createNumberMatcher = (opts) => anchoredRegex(RegexPatterns.negativeLookahead(anchoredNegativeZeroPattern) + | ||
RegexPatterns.nonCapturingGroup("-?" + | ||
RegexPatterns.nonCapturingGroup(RegexPatterns.nonCapturingGroup("0|" + positiveIntegerPattern) + | ||
RegexPatterns.nonCapturingGroup(opts.decimalPattern) + | ||
"?") + | ||
(opts.allowDecimalOnly ? "" : "|" + opts.decimalPattern) + | ||
"?")); | ||
/** | ||
@@ -18,4 +30,17 @@ * Matches a well-formatted numeric expression according to the following rules: | ||
*/ | ||
export const wellFormedNumberMatcher = /^(?!^-0$)-?(?:0|[1-9]\d*)(?:\.\d*[1-9])?$/; | ||
export const wellFormedNumberMatcher = createNumberMatcher({ | ||
decimalPattern: strictDecimalPattern, | ||
allowDecimalOnly: false | ||
}); | ||
export const isWellFormedNumber = wellFormedNumberMatcher.test.bind(wellFormedNumberMatcher); | ||
/** | ||
* Similar to wellFormedNumber but more permissive in the following ways: | ||
* | ||
* - Allows numbers without an integer portion like ".5" (well-formed equivalent is "0.5") | ||
* - Allows decimals with trailing zeroes like "0.10" (well-formed equivalent is "0.1") | ||
*/ | ||
export const numericStringMatcher = createNumberMatcher({ | ||
decimalPattern: looseDecimalPattern, | ||
allowDecimalOnly: true | ||
}); | ||
export const numberLikeMatcher = /^-?\d*\.?\d*$/; | ||
@@ -28,3 +53,5 @@ const isNumberLike = (s) => s.length !== 0 && numberLikeMatcher.test(s); | ||
*/ | ||
export const wellFormedIntegerMatcher = /^(?:0|(?:-?[1-9]\d*))$/; | ||
export const wellFormedIntegerMatcher = anchoredRegex(RegexPatterns.negativeLookahead("^-0$") + | ||
"-?" + | ||
RegexPatterns.nonCapturingGroup(RegexPatterns.nonCapturingGroup("0|" + positiveIntegerPattern))); | ||
export const isWellFormedInteger = wellFormedIntegerMatcher.test.bind(wellFormedIntegerMatcher); | ||
@@ -31,0 +58,0 @@ export const integerLikeMatcher = /^-?\d+$/; |
@@ -5,2 +5,3 @@ import type { array } from "./arrays.ts"; | ||
import type { Key } from "./keys.ts"; | ||
import type { intersectUnion } from "./unionToTuple.ts"; | ||
export type Dict<k extends string = string, v = unknown> = { | ||
@@ -22,2 +23,5 @@ readonly [_ in k]: v; | ||
}>; | ||
export type unionToPropwiseXor<props extends object, branchKey extends PropertyKey = keyof intersectUnion<props>> = props extends infer distributed ? show<distributed & { | ||
[k in branchKey]?: k extends keyof distributed ? unknown : undefined; | ||
}> : never; | ||
export type requireKeys<o, key extends keyof o> = o & { | ||
@@ -24,0 +28,0 @@ [requiredKey in key]-?: defined<o[requiredKey]>; |
@@ -1,2 +0,2 @@ | ||
export declare const arkUtilVersion = "0.25.0"; | ||
export declare const arkUtilVersion = "0.26.0"; | ||
export declare const initialRegistryContents: { | ||
@@ -3,0 +3,0 @@ version: string; |
@@ -8,3 +8,3 @@ import { domainOf } from "./domain.js"; | ||
// For now, we assert this matches the package.json version via a unit test. | ||
export const arkUtilVersion = "0.25.0"; | ||
export const arkUtilVersion = "0.26.0"; | ||
export const initialRegistryContents = { | ||
@@ -11,0 +11,0 @@ version: arkUtilVersion, |
@@ -11,2 +11,6 @@ export declare const capitalize: <s extends string>(s: s) => Capitalize<s>; | ||
export declare const deanchoredSource: (regex: RegExp | string) => string; | ||
export declare const RegexPatterns: { | ||
negativeLookahead: (pattern: string) => `(?!${string})`; | ||
nonCapturingGroup: (pattern: string) => `(?:${string})`; | ||
}; | ||
export declare const escapeChar = "\\"; | ||
@@ -13,0 +17,0 @@ export type EscapeChar = typeof escapeChar; |
@@ -15,2 +15,6 @@ export const capitalize = (s) => (s[0].toUpperCase() + s.slice(1)); | ||
}; | ||
export const RegexPatterns = { | ||
negativeLookahead: (pattern) => `(?!${pattern})`, | ||
nonCapturingGroup: (pattern) => `(?:${pattern})` | ||
}; | ||
export const escapeChar = "\\"; | ||
@@ -17,0 +21,0 @@ export const whitespaceChars = { |
{ | ||
"name": "@ark/util", | ||
"version": "0.25.0", | ||
"version": "0.26.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": { |
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
103501
2268