{"id":22616330,"url":"https://github.com/xpepermint/typeablejs","last_synced_at":"2025-10-04T05:43:33.005Z","repository":{"id":57383334,"uuid":"67285240","full_name":"xpepermint/typeablejs","owner":"xpepermint","description":"A library for checking and casting types.","archived":false,"fork":false,"pushed_at":"2022-12-29T04:00:19.000Z","size":137,"stargazers_count":19,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T08:42:41.083Z","etag":null,"topics":["type","typecast"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xpepermint.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-03T10:46:40.000Z","updated_at":"2024-06-10T01:33:18.000Z","dependencies_parsed_at":"2023-01-31T08:00:25.760Z","dependency_job_id":null,"html_url":"https://github.com/xpepermint/typeablejs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Ftypeablejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Ftypeablejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Ftypeablejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Ftypeablejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xpepermint","download_url":"https://codeload.github.com/xpepermint/typeablejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248034944,"owners_count":21037084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["type","typecast"],"created_at":"2024-12-08T19:12:09.312Z","updated_at":"2025-10-04T05:43:27.942Z","avatar_url":"https://github.com/xpepermint.png","language":"JavaScript","readme":"![Build Status](https://travis-ci.org/xpepermint/typeablejs.svg?branch=master)\u0026nbsp;[![NPM Version](https://badge.fury.io/js/typeable.svg)](https://badge.fury.io/js/typeable)\u0026nbsp;[![Dependency Status](https://gemnasium.com/xpepermint/typeablejs.svg)](https://gemnasium.com/xpepermint/typeablejs)\n\n# typeable.js\n\n\u003e A library for checking and casting types.\n\nThis is a light weight open source package for use on **server** or in **browser** (using module bundler). The source code is available on [GitHub](https://github.com/xpepermint/typeablejs) where you can also find our [issue tracker](https://github.com/xpepermint/typeablejs/issues).\n\n## Related Projects\n\n* [RawModel.js](https://github.com/xpepermint/rawmodeljs): Strongly-typed JavaScript object with support for validation and error handling.\n* [Validatable.js](https://github.com/xpepermint/validatablejs): A library for synchronous and asynchronous validation.\n* [Handleable.js](https://github.com/xpepermint/handleablejs): A library for synchronous and asynchronous error handling.\n\n## Install\n\nRun the command below to install the package.\n\n```\n$ npm install --save typeable\n```\n\n## Examples\n\n```js\nimport {cast} from 'typeable';\n\n// general use\ncast(100, 'String'); // =\u003e '100'\ncast('true', 'Boolean'); // =\u003e true\ncast('10.13', 'Integer'); // =\u003e 10\ncast('10.13', 'Float'); // =\u003e 10.13\ncast('10.13', 'Number'); // =\u003e 10.13\ncast(1229380112300, 'Date'); // =\u003e Date(2008-12-15T22:28:32.300Z)\ncast('John', ['Any']); // =\u003e ['John']\ncast(100, ['String']); // =\u003e ['100']\ncast([100], ['String']); // =\u003e ['100']\ncast('true', ['Boolean']); // =\u003e [true]\ncast(['true'], ['Boolean']); // =\u003e [true]\ncast('10.13', ['Integer']); // =\u003e [10]\ncast(['10.13'], ['Integer']); // =\u003e [10]\ncast('10.13', ['Float']); // =\u003e [10.13]\ncast(['10.13'], ['Float']); // =\u003e [10.13]\ncast('10.13', ['Number']); // =\u003e [10.13]\ncast(['10.13'], ['Number']); // =\u003e [10.13]\ncast(1229380112300, ['Date']); // =\u003e [Date(2008-12-15T22:28:32.300Z)]\ncast([1229380112300], ['Date']); // =\u003e [Date(2008-12-15T22:28:32.300Z)]\n\n// short syntax\ncast('10.13', 'Integer'); // =\u003e 10\n\n// custom types\ncast('value', (value) =\u003e `custom ${value}`); // =\u003e 'custom value'\n```\n\n## API\n\n### Data Types\n\n| Type | Description\n|------|------------\n| 'Any' | A value of different types (excluding arrays).\n| ['Any'] | An array with values of different types.\n| 'String' | A string value.\n| ['String'] | An array of string values.\n| 'Boolean' | A boolean value.\n| ['Boolean'] | An array of boolean values.\n| 'Number' | An integer or a float number.\n| ['Number'] | An array of integer or float numbers.\n| 'Integer' | An integer number.\n| ['Integer'] | An array of integer numbers.\n| 'Float' | A float number.\n| ['Float'] | An array of float numbers.\n| 'Date' | A date.\n| ['Date'] | An array of dates.\n| Function | Custom type.\n| [Function] | Custom type.\n\n### Methods\n\n**cast(value, type)**:Any\n\u003e Converts the `value` to the specified `type`.\n\n| Name | Type | Required | Default | Description\n|------|------|----------|---------|------------\n| value | Any | Yes | - | A value to be casted.\n| type | String | Yes | - | Data type name.\n\n**isAbsent(value)**:Boolean\n\u003e Returns `true` if the `value` represents an empty value.\n\n**isArray(value)**:Boolean\n\u003e Returns `true` if the `value` is an array.\n\n**isBoolean(value)**:Boolean\n\u003e Returns `true` if the `value` is a boolean value.\n\n**isClass(value)**:Boolean\n\u003e Returns `true` if the `value` represents a class object.\n\n**isDate(value)**:Boolean\n\u003e Returns `true` if the `value` is a date object.\n\n**isFloat(value)**:Boolean\n\u003e Returns `true` if the `value` is a float number.\n\n**isFunction(value)**:Boolean\n\u003e Returns `true` if the `value` represents a function.\n\n**isInfinite(value)**:Boolean\n\u003e Returns `true` if the provided `value` represents infinite number.\n\n**isInteger(value)**:Boolean\n\u003e Returns `true` if the `value` is an integer number.\n\n**isNull(value)**:Boolean\n\u003e Returns `true` if the provided `value` is `null`.\n\n**isNumber(value)**:Boolean\n\u003e Returns `true` if the `value` is a number.\n\n**isObject(value)**:Boolean\n\u003e Returns `true` if the `value` is an object (an object with keys).\n\n**isPresent(value)**:Boolean\n\u003e Returns `true` if the `value` represents a present value.\n\n**isPromise(value)**:Boolean\n\u003e Returns `true` if the `value` represents a promise object.\n\n**isString(value)**:Boolean\n\u003e Returns `true` if the `value` is a string value.\n\n**isUndefined(value)**:Boolean\n\u003e Returns `true` if the provided `value` is of type `undefined`.\n\n**isValue(value)**:Boolean\n\u003e Returns `true` if the `value` is some sort of expected value.\n\n**toArray(value)**:Array\n\u003e Converts the `value` to an array object.\n\n**toBoolean(value)**:Boolean\n\u003e Converts the `value` to a boolean value.\n\n**toDate(value)**:Date\n\u003e Converts the `value` to a date object.\n\n**toFloat(value)**:Number\n\u003e Converts the `value` to a float value.\n\n**toInteger(value)**:Number\n\u003e Converts the `value` to an integer value.\n\n**toNumber(value)**:Number\n\u003e Converts the `value` to a number value.\n\n**toString(value)**:String\n\u003e Converts the `value` to a string value.\n\n## License (MIT)\n\n```\nCopyright (c) 2016 Kristijan Sedlak \u003cxpepermint@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpepermint%2Ftypeablejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxpepermint%2Ftypeablejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpepermint%2Ftypeablejs/lists"}