{"id":15978252,"url":"https://github.com/jamashita/anden","last_synced_at":"2026-01-31T14:03:28.261Z","repository":{"id":38423807,"uuid":"334980128","full_name":"jamashita/anden","owner":"jamashita","description":"Fundamental classes for OOP in TypeScript","archived":false,"fork":false,"pushed_at":"2024-11-18T23:57:16.000Z","size":4231,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T12:12:36.323Z","etag":null,"topics":["ddd","entity","oop","typescript","ulid","uuid","valueobject"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamashita.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-01T14:42:50.000Z","updated_at":"2024-07-19T19:49:59.000Z","dependencies_parsed_at":"2023-02-16T23:46:13.152Z","dependency_job_id":"25aaa3aa-3178-4d63-8e31-de7d538981d4","html_url":"https://github.com/jamashita/anden","commit_stats":{"total_commits":814,"total_committers":4,"mean_commits":203.5,"dds":0.4643734643734644,"last_synced_commit":"6653f1541bea631a8895487b7fa85fd3387a56f7"},"previous_names":[],"tags_count":287,"template":false,"template_full_name":null,"purl":"pkg:github/jamashita/anden","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamashita%2Fanden","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamashita%2Fanden/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamashita%2Fanden/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamashita%2Fanden/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamashita","download_url":"https://codeload.github.com/jamashita/anden/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamashita%2Fanden/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28944789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T13:02:32.153Z","status":"ssl_error","status_checked_at":"2026-01-31T13:00:07.528Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ddd","entity","oop","typescript","ulid","uuid","valueobject"],"created_at":"2024-10-07T23:07:26.855Z","updated_at":"2026-01-31T14:03:28.242Z","avatar_url":"https://github.com/jamashita.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anden\n\nThis package allows you to represent many classes using a unified interface.\n\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\n[![CI](https://github.com/jamashita/anden/actions/workflows/ci.yml/badge.svg)](https://github.com/jamashita/anden/actions/workflows/ci.yml)\n\n## Install\n\n```text\nyarn add @jamashita/anden\n```\n\n## Prerequisite\n\n```\n\u003e node -v\nv20.12.2\n\n\u003e npm -v\n10.5.0\n\n\u003e yarn -v\n1.22.21\n```\n\n## Conventional commit\n\n```\ngit cz\n```\n\n# Error classes\n\n## RuntimeError\n\nA basic error class that extends the built-in `Error` class and can contain other `Error` instances as a property.\n\n```ts\nthrow new RuntimeError('An error occured.', error);\n```\n\n## Errors\\\u003cE extends Error = Error\\\u003e\n\nThis error class can hold multiple `Error` instances at once, and it extends the `RuntimeError` class.\n\n```ts\nthrow new Errors(new Error('Error 1'), new Error('Error 2'), new Error('Error 3'));\n```\n\n## ExhaustiveError\n\nThis error class can be used to detect cases that are not handled in a switch. TypeScript will generate an alert when\nthere is an unhandled case and this error is included in the default clause.\n\n## UnimplementedError\n\nThis error class is mainly used to indicate that a method is not yet implemented and it extends the `RuntimeError`\nclass.\n\n```ts\nthrow new UnimplementedError('This method is not yet implemented');\n````\n\n# Object classes\n\n## Objet\n\nA class that redefines the built-in `Object`.\n\n### `Objet.genHashCode(obj: object): string`\n\nGenerates a hash code for the given `obj`. If the object's properties have the same values, this method will return the\nsame hash code.\n\n### `Objet.identify(n: unknown): string`\n\nConverts the given`n` to string. If `n` has a `toString()` method, the result of calling that method is\nreturned. Otherwise, the result of `String(n)` is returned.\n\n### (abstract) `Objet.prototype.serialize(): string`\n\nThis method is used in `Objet.prototype.toString()` to customize the string representation of an object. It is strongly\nrecommended to implement this method when extending the `Objet` class.\n\n### `Objet.prototype.equals(other: unknown): boolean`\n\nCompares the hash code of this instance with the hash code of the given `other`, and returns `true` if they are the\nsame.\n\n### `Objet.prototype.hashCode(): string`\n\nReturns the hash code of this instance. If the properties have the same values, this method must return the same hash\ncode.\n\n### `Objet.prototype.toString(): string`\n\nCalls and returns the result of the `Objet.prototype.serialize()` method.\n\n## Entity\\\u003cI\\\u003e\n\nA class for entities in Domain-Driven Design (DDD). It is a concrete class extending the `Objet` class, and `I` is an\nidentifier class.\n\n### (abstract) `Entity.prototype.getIdentifier(): I`\n\nReturns the identifier of the entity. It is used in the `entity.equals(other: unknown): boolean` method to compare two\nentities.\n\n### (override) `Entity.prototype.equals(other: unknown): boolean`\n\nCompares the identifier of this object with the identifier of the given `other`. Returns `true` if they are the same.\nThis method should not be overridden, as it relies on the correct implementation of\nthe `Entity.prototype.getIdentifier()` method.\n\n## ValueObject\n\nA class for value objects in Domain-Driven Design (DDD). It is a concrete class extending the `Objet` class.\n\n## Reference\n\nA class to check for circular references in an object.\n\n### `Reference.isCircular(value: unknown): boolean`\n\nReturns `true` if the given `value` has circular references.\n\n# Type classes\n\n### BigIntValidation\n\nUsed for methods. If the given value does not meet this requirement, `TypeError` will be thrown.\n\n```ts\nclass Klazz {\n  @Validate()\n  public doSomething(@BigIntValidation({\n    conditions: [\n      {\n        operator: '\u003e=',\n        value: 3n\n      },\n      {\n        operator: '\u003c=',\n        value: 5n\n      }\n    ]\n  }) n1: bigint): void {\n    //\n  }\n}\n```\n\n### BooleanValidation\n\nUsed for methods. If the given value does not meet this requirement, `TypeError` will be thrown.\n\n```ts\nclass Klazz {\n  @Validate()\n  public doSomething(@BooleanValidation() n1: boolean): void {\n    //\n  }\n}\n```\n\n### NumberValidation\n\nUsed for methods. If the given value does not meet this requirement, `TypeError` will be thrown.\n\n```ts\nclass Klazz {\n  @Validate()\n  public doSomething(@NumberValidation({\n    conditions: [\n      {\n        operator: '\u003e=',\n        value: 3\n      },\n      {\n        operator: '\u003c=',\n        value: 5\n      }\n    ],\n    int: false,\n    noNaN: true,\n    noInfinity: true\n  }) n1: number): void {\n    //\n  }\n}\n```\n\n### StringValidation\n\nUsed for methods. If the given value does not meet this requirement, `TypeError` will be thrown.\n\n```ts\nclass Klazz {\n  @Validate()\n  public doSomething(@StringValidation({\n    type: 'length',\n    min: 1,\n    max: 100\n  }) n1: string): void {\n    //\n  }\n}\n```\n\n### SymbolValidation\n\nUsed for methods. If the given value does not meet this requirement, `TypeError` will be thrown.\n\n```ts\nclass Klazz {\n  @Validate()\n  public doSomething(@SymbolValidation() n1: symbol): void {\n    //\n  }\n}\n```\n\nA class for creating a deep copy of an object literal. This class does not check whether the given object literal has\ncircular references or not.\n\n### `Clone.copy\u003cT extends ObjectLiteral\u003e(obj: T): T`\n\nCreates a deep copy of the given object literal.\n\n## (interface) Cloneable\u003cT\u003e\n\nAn interface for objects that can be cloned.\n\n### `Cloneable.prototype.duplicate(): T`\n\nShould return a deep copy of itself.\n\n### `isCloneable(n: unknown): n is Cloneable\u003cT\u003e`\n\nReturns `true` if the given `n` has a `duplicate` method.\n\n## Equality\n\nA class for checking the equality of two object literals. This class does not check whether the given object literals\nhave circular references or not.\n\n### `Equality.same(n1: ObjectLiteral, n2: ObjectLiteral): boolean`\n\nReturns `true` if the two given object literals are the same, `false` otherwise.\n\n## (interface) Equatable\n\nAn interface for objects that can be compared for equality.\n\n### `Equatable.prototype.equals(other: unknown): boolean`\n\nShould return `true` if this and the given object are the same, `false` otherwise.\n\n## (interface) JSONifiable\\\u003cO extends ObjectLiteral\\\u003e\n\nAn interface for objects that can be converted to a JSON object.\n\n### `JSONifiable.prototype.toJSON(): O`\n\nReturns the JSON representation of this object.\n\n### `isJSONifiable(n: unknown): n is JSONifiable\u003cO\u003e`\n\nReturns `true` if the given `n` has a `toJSON` method, `false` otherwise.\n\n## Kind\n\nClass for type narrowing.\n\n### `Kind.isArray\u003cT = unknown\u003e(value: unknown): value is Array\u003cT\u003e`\n\n### `Kind.isBigInt(value: unknown): value is BigInt`\n\n### `Kind.isBoolean(value: unknown): value is Boolean`\n\n### `Kind.isClass\u003cT extends Constructor\u003e(instance: unknown, klazz: T): instance is T`\n\n### `Kind.isFunction(value: unknown): value is Function`\n\n### `Kind.isInteger(value: unknown): value is Integer`\n\n### `Kind.isNaN(value: unknown): boolean`\n\n### `Kind.isNone(value: unknown): value is null | undefined | void`\n\n### `Kind.isNull(value: unknown): value is null`\n\n### `Kind.isNumber(value: unknown): value is number`\n\n### `Kind.isNumericalString(value: unknown): value is NumericalString`\n\n### `Kind.isObject\u003cT extends object = object\u003e(value: unknown): value is Vague\u003cT\u003e`\n\n### `Kind.isPrimitive(value: unknown): value is Primitive`\n\n### `Kind.isPromiseLike\u003cT = unknown\u003e(value: unknown): value is PromiseLike\u003cT\u003e`\n\n### `Kind.isString(value: unknown): value is string`\n\n### `Kind.isSymbol(value: unknown): value is symbol`\n\n### `Kind.isSUndefined(value: unknown): value is undefined`\n\n## (interface) Nominative\n\nAn interface that extends both `Equatable` and `Serializable` interfaces.\n\n### `Nominative.prototype.hashCode(): string`\n\nReturns a hash code of this instance.\n\n## (interface) Serializable\n\nAn interface for objects that can be converted to a string.\n\n### `Serializable.prototype.serialize(): string`\n\nReturns a string representation of this instance.\n\n# ULID class\n\n## ULID\n\nA class for generating and working with ULIDs (Universally Unique Lexicographically Sortable Identifier),\nextends `ValueObject`.\n\n### `ULID.generate(): ULID`\n\nReturns a new ULID instance with a randomly generated ULID value.\n\n### `ULID.of(id: string): ULID`\n\nReturns a new ULID instance from the given string. May throw a `ULIDError` if the given `id` is not a valid ULID.\n\n### `ULID.regex(): RegExp`\n\nReturns the regular expression used for validating ULIDs.\n\n### `ULID.size(): number`\n\nReturns the length of a ULID.\n\n### `ULID.validate(str: string): boolean`\n\nReturns `true` if the given string is a valid ULID, `false` otherwise.\n\n### ULIDValidation\n\nUsed for methods. If the given value does not meet this requirement, `TypeError` will be thrown.\n\n```ts\nclass Klazz {\n  @Validate()\n  public doSomething(@ULIDValidation() n1: string): void {\n    //\n  }\n}\n```\n\n# UUID class\n\n## UUID\n\nA class for generating and working with UUIDs (Universally Unique Identifiers), extends `ValueObject`.\n\n### `UUID.of(id: string): UUID`\n\nReturns a new UUID instance from the given string. May throw a `UUIDError` if the given `id` is not a valid UUID.\n\n### `UUID.regex(): RegExp`\n\nReturns the regular expression used for validating UUIDs.\n\n### `UUID.size(): number`\n\nReturns the length of a UUID.\n\n### `UUID.v4(): UUID`\n\nReturns a new v4 UUID instance.\n\n### `UUID.v5(): UUID`\n\nReturns a new v5 UUID instance.\n\n### `UUID.v6(): UUID`\n\nReturns a new v6 UUID instance.\n\n### `UUID.v7(): UUID`\n\nReturns a new v7 UUID instance.\n\n### `UUID.validate(str: string): boolean`\n\nReturns `true` if the given string is a valid UUID, `false` otherwise.\n\n### UUIDValidation\n\nUsed for methods. If the given value does not meet this requirement, `TypeError` will be thrown.\n\n```ts\nclass Klazz {\n  @Validate()\n  public doSomething(@UUIDValidation() n1: string): void {\n    //\n  }\n}\n```\n\n# Zeit class\n\n## Zeit\n\nA class for working with date and time, extends `ValueObject`.\n\n### `Zeit.earliest(zeiten: Iterable\u003cZeit\u003e): Zeit`\n\nReturns the earliest `Zeit` instance from the given iterable of `Zeit`. May throw `ZeitError` if the given `zeiten` is\nempty.\n\n### `Zeit.latest(zeiten: Iterable\u003cZeit\u003e): Zeit`\n\nReturns the latest `Zeit` instance from the given iterable of `Zeit`. May throw `ZeitError` if the given `zeiten` is\nempty.\n\n### `Zeit.now(): Zeit`\n\nReturns the current date and time as a `Zeit` instance.\n\n### `Zeit.of(zeit: dayjs.Dayjs): Zeit`\n\nReturns a new `Zeit` instance from the given `dayjs` instance.\n\n### `Zeit.ofDate(date: Date): Zeit`\n\nReturns a new `Zeit` instance from the given `Date` instance.\n\n### `Zeit.ofString(str: string, format: string): Zeit`\n\nReturns a new `Zeit` instance from the given `str` using the given `format`. May throw `ZeitError` if the given `str`\ncannot be parsed using the given format.\n\n### `Zeit.validate(str: string, format: string): boolean`\n\nReturns `true` if the given `str` can be parsed using the given `format`.\n\n### `Zeit.prototype.advance(value: number, unit: ZeitUnitType): Zeit`\n\nReturns a new `Zeit` instance that is `value` `unit` earlier than this instance.\n\n```ts\nconst zeit1: Zeit = Zeit.ofString('2000-04-02');\nconst zeit2: Zeit = zeit1.advance(1, 'day')\n\nconsole.log(zeit2.toString('YYYY-MM-DD'));\n// '2000-04-01'\n```\n\n### `Zeit.prototype.isAfter(other: Zeit): boolean`\n\nReturns `true` if this instance is after the given `other` `Zeit` instance.\n\n### `Zeit.prototype.isBefore(other: Zeit): boolean`\n\nReturns `true` if this instance is before the given `other` `Zeit` instance.\n\n### `Zeit.prototype.isValid(): boolean`\n\nReturns `true` if this instance represents a valid date and time.\n\n### `Zeit.prototype.postpone(value: number, unit: ZeitUnitType): Zeit`\n\nReturns a new Zeit instance that is `value` `unit` later than this instance.\n\n```ts\nconst zeit1: Zeit = Zeit.ofString('2000-04-02');\nconst zeit2: Zeit = zeit1.postpone(1, 'day')\n\nconsole.log(zeit2.toString('YYYY-MM-DD'));\n// '2000-04-03'\n```\n\n### (override) `Zeit.prototype.toString(format?: string): boolean`\n\n### ZeitValidation\n\nUsed for methods. If the given value does not meet this requirement, `TypeError` will be thrown.\n\n```ts\nclass Klazz {\n  @Validate()\n  public doSomething(@ZeitValidation({\n    format: 'YYYY-MM-DD'\n  }) n1: string): void {\n    //\n  }\n}\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamashita%2Fanden","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamashita%2Fanden","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamashita%2Fanden/lists"}