Skip to content

Commit

Permalink
style: deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Oct 23, 2024
1 parent e75ee63 commit c217398
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/datetime/localDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ export class LocalDate {
setYear(v: number): LocalDate {
return this.set('year', v)
}

setMonth(v: number): LocalDate {
return this.set('month', v)
}

setDay(v: number): LocalDate {
return this.set('day', v)
}
Expand Down Expand Up @@ -143,28 +145,35 @@ export class LocalDate {
isToday(): boolean {
return this.isSame(localDate.today())
}

isAfterToday(): boolean {
return this.isAfter(localDate.today())
}

isSameOrAfterToday(): boolean {
return this.isSameOrAfter(localDate.today())
}

isBeforeToday(): boolean {
return this.isBefore(localDate.today())
}

isSameOrBeforeToday(): boolean {
return this.isSameOrBefore(localDate.today())
}

getAgeInYears(today?: LocalDateInput): number {
return this.getAgeIn('year', today)
}

getAgeInMonths(today?: LocalDateInput): number {
return this.getAgeIn('month', today)
}

getAgeInDays(today?: LocalDateInput): number {
return this.getAgeIn('day', today)
}

getAgeIn(unit: LocalDateUnit, today?: LocalDateInput): number {
return localDate.fromInput(today || new Date()).diff(this, unit)
}
Expand Down Expand Up @@ -264,24 +273,31 @@ export class LocalDate {
plusDays(num: number): LocalDate {
return this.plus(num, 'day')
}

plusWeeks(num: number): LocalDate {
return this.plus(num, 'week')
}

plusMonths(num: number): LocalDate {
return this.plus(num, 'month')
}

plusYears(num: number): LocalDate {
return this.plus(num, 'year')
}

minusDays(num: number): LocalDate {
return this.plus(-num, 'day')
}

minusWeeks(num: number): LocalDate {
return this.plus(-num, 'week')
}

minusMonths(num: number): LocalDate {
return this.plus(-num, 'month')
}

minusYears(num: number): LocalDate {
return this.plus(-num, 'year')
}
Expand Down
39 changes: 39 additions & 0 deletions src/datetime/localTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,42 +212,55 @@ export class LocalTime {
get year(): number {
return this.$date.getFullYear()
}

setYear(v: number): LocalTime {
return this.set('year', v)
}

get month(): number {
return this.$date.getMonth() + 1
}

setMonth(v: number): LocalTime {
return this.set('month', v)
}

get week(): number {
return getWeek(this.$date)
}

setWeek(v: number): LocalTime {
return this.set('week', v)
}

get day(): number {
return this.$date.getDate()
}

setDay(v: number): LocalTime {
return this.set('day', v)
}

get hour(): number {
return this.$date.getHours()
}

setHour(v: number): LocalTime {
return this.set('hour', v)
}

get minute(): number {
return this.$date.getMinutes()
}

setMinute(v: number): LocalTime {
return this.set('minute', v)
}

get second(): number {
return this.$date.getSeconds()
}

setSecond(v: number): LocalTime {
return this.set('second', v)
}
Expand All @@ -258,6 +271,7 @@ export class LocalTime {
get dayOfWeek(): ISODayOfWeek {
return (this.$date.getDay() || 7) as ISODayOfWeek
}

setDayOfWeek(v: ISODayOfWeek): LocalTime {
_assert(VALID_DAYS_OF_WEEK.has(v), `Invalid dayOfWeek: ${v}`)
const dow = this.$date.getDay() || 7
Expand Down Expand Up @@ -292,42 +306,55 @@ export class LocalTime {
plusSeconds(num: number): LocalTime {
return this.plus(num, 'second')
}

plusMinutes(num: number): LocalTime {
return this.plus(num, 'minute')
}

plusHours(num: number): LocalTime {
return this.plus(num, 'hour')
}

plusDays(num: number): LocalTime {
return this.plus(num, 'day')
}

plusWeeks(num: number): LocalTime {
return this.plus(num, 'week')
}

plusMonths(num: number): LocalTime {
return this.plus(num, 'month')
}

plusYears(num: number): LocalTime {
return this.plus(num, 'year')
}

minusSeconds(num: number): LocalTime {
return this.plus(-num, 'second')
}

minusMinutes(num: number): LocalTime {
return this.plus(-num, 'minute')
}

minusHours(num: number): LocalTime {
return this.plus(-num, 'hour')
}

minusDays(num: number): LocalTime {
return this.plus(-num, 'day')
}

minusWeeks(num: number): LocalTime {
return this.plus(-num, 'week')
}

minusMonths(num: number): LocalTime {
return this.plus(-num, 'month')
}

minusYears(num: number): LocalTime {
return this.plus(-num, 'year')
}
Expand Down Expand Up @@ -452,20 +479,25 @@ export class LocalTime {
isSame(d: LocalTimeInput): boolean {
return this.compare(d) === 0
}

isBefore(d: LocalTimeInput, inclusive = false): boolean {
const r = this.compare(d)
return r === -1 || (r === 0 && inclusive)
}

isSameOrBefore(d: LocalTimeInput): boolean {
return this.compare(d) <= 0
}

isAfter(d: LocalTimeInput, inclusive = false): boolean {
const r = this.compare(d)
return r === 1 || (r === 0 && inclusive)
}

isSameOrAfter(d: LocalTimeInput): boolean {
return this.compare(d) >= 0
}

isBetween(min: LocalTimeInput, max: LocalTimeInput, incl: Inclusiveness = '[)'): boolean {
let r = this.compare(min)
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
Expand Down Expand Up @@ -518,28 +550,35 @@ export class LocalTime {
getAgeInYears(now?: LocalTimeInput): number {
return this.getAgeIn('year', now)
}

getAgeInMonths(now?: LocalTimeInput): number {
return this.getAgeIn('month', now)
}

getAgeInDays(now?: LocalTimeInput): number {
return this.getAgeIn('day', now)
}

getAgeInHours(now?: LocalTimeInput): number {
return this.getAgeIn('hour', now)
}

getAgeInMinutes(now?: LocalTimeInput): number {
return this.getAgeIn('minute', now)
}

getAgeInSeconds(now?: LocalTimeInput): number {
return this.getAgeIn('second', now)
}

getAgeIn(unit: LocalTimeUnit, now?: LocalTimeInput): number {
return localTime.fromInput(now ?? new Date()).diff(this, unit)
}

isAfterNow(): boolean {
return this.$date.valueOf() > Date.now()
}

isBeforeNow(): boolean {
return this.$date.valueOf() < Date.now()
}
Expand Down
20 changes: 20 additions & 0 deletions src/json-schema/jsonSchemaBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,38 +131,47 @@ export class JsonSchemaAnyBuilder<T = unknown, SCHEMA_TYPE extends JsonSchema<T>
Object.assign(this.schema, { $schema })
return this
}

$schemaDraft7(): this {
this.$schema('http://json-schema.org/draft-07/schema#')
return this
}

$id($id: string): this {
Object.assign(this.schema, { $id })
return this
}

title(title: string): this {
Object.assign(this.schema, { title })
return this
}

description(description: string): this {
Object.assign(this.schema, { description })
return this
}

deprecated(deprecated = true): this {
Object.assign(this.schema, { deprecated })
return this
}

type(type: string): this {
Object.assign(this.schema, { type })
return this
}

default(v: any): this {
Object.assign(this.schema, { default: v })
return this
}

oneOf(schemas: JsonSchema[]): this {
Object.assign(this.schema, { oneOf: schemas })
return this
}

allOf(schemas: JsonSchema[]): this {
Object.assign(this.schema, { allOf: schemas })
return this
Expand Down Expand Up @@ -211,18 +220,22 @@ export class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder<number, JsonSc
Object.assign(this.schema, { multipleOf })
return this
}

min(minimum: number): this {
Object.assign(this.schema, { minimum })
return this
}

exclusiveMin(exclusiveMinimum: number): this {
Object.assign(this.schema, { exclusiveMinimum })
return this
}

max(maximum: number): this {
Object.assign(this.schema, { maximum })
return this
}

exclusiveMax(exclusiveMaximum: number): this {
Object.assign(this.schema, { exclusiveMaximum })
return this
Expand Down Expand Up @@ -264,14 +277,17 @@ export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder<string, JsonSc
Object.assign(this.schema, { pattern })
return this
}

min(minLength: number): this {
Object.assign(this.schema, { minLength })
return this
}

max(maxLength: number): this {
Object.assign(this.schema, { maxLength })
return this
}

length(minLength: number, maxLength: number): this {
Object.assign(this.schema, { minLength, maxLength })
return this
Expand Down Expand Up @@ -358,10 +374,12 @@ export class JsonSchemaObjectBuilder<T extends AnyObject> extends JsonSchemaAnyB
Object.assign(this.schema, { minProperties })
return this
}

maxProps(maxProperties: number): this {
Object.assign(this.schema, { maxProperties })
return this
}

additionalProps(additionalProperties: boolean): this {
Object.assign(this.schema, { additionalProperties })
return this
Expand Down Expand Up @@ -400,10 +418,12 @@ export class JsonSchemaArrayBuilder<ITEM> extends JsonSchemaAnyBuilder<
Object.assign(this.schema, { minItems })
return this
}

max(maxItems: number): this {
Object.assign(this.schema, { maxItems })
return this
}

unique(uniqueItems: number): this {
Object.assign(this.schema, { uniqueItems })
return this
Expand Down
2 changes: 2 additions & 0 deletions src/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export class Semver {
get major(): number {
return this.tokens[0]
}

get minor(): number {
return this.tokens[1]
}

get patch(): number {
return this.tokens[2]
}
Expand Down
Loading

0 comments on commit c217398

Please sign in to comment.