{"id":26452929,"url":"https://github.com/defaultsbotdevelopment/dbd-tools","last_synced_at":"2026-05-06T06:33:32.637Z","repository":{"id":129111759,"uuid":"521198372","full_name":"DefaultsBotDevelopment/DBD-Tools","owner":"DefaultsBotDevelopment","description":"Provides usefull functions to help you create your dream projects!","archived":false,"fork":false,"pushed_at":"2024-01-19T23:25:12.000Z","size":220,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-30T00:37:04.469Z","etag":null,"topics":["arrays","convert","discord","objects","parser","time","tools","utility"],"latest_commit_sha":null,"homepage":"https://discord.gg/5xEwm8e6Vy","language":"TypeScript","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/DefaultsBotDevelopment.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-08-04T09:10:57.000Z","updated_at":"2024-02-25T21:08:27.000Z","dependencies_parsed_at":"2023-07-24T14:21:11.404Z","dependency_job_id":"8851698f-a11c-4b41-b9e7-5163ac52e236","html_url":"https://github.com/DefaultsBotDevelopment/DBD-Tools","commit_stats":null,"previous_names":["default-01/js-tools","defaultsbotdevelopment/dbd-tools"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DefaultsBotDevelopment%2FDBD-Tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DefaultsBotDevelopment%2FDBD-Tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DefaultsBotDevelopment%2FDBD-Tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DefaultsBotDevelopment%2FDBD-Tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DefaultsBotDevelopment","download_url":"https://codeload.github.com/DefaultsBotDevelopment/DBD-Tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244280144,"owners_count":20427731,"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":["arrays","convert","discord","objects","parser","time","tools","utility"],"created_at":"2025-03-18T18:28:58.624Z","updated_at":"2025-10-10T22:18:00.675Z","avatar_url":"https://github.com/DefaultsBotDevelopment.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://img.shields.io/npm/v/@defaultsbotdevelopment/dbd-tools.svg?style=flat-square)](https://www.npmjs.org/package/@defaultsbotdevelopment/dbd-tools)\n\n# Default's Bot Development Tools\n\nA collection of JavaScript utility functions.\n\n## Installation\n\nTo install the package, run the following command:\n\n```bash\nnpm install @defaultsbotdevelopment/dbd-tools\n```\n\n## Usage\n\nIn your project, import the package either using `require` or `import`:\n\n```js\nconst dbdTools = require('@defaultsbotdevelopment/dbd-tools');\n// or\nimport dbdTools from '@defaultsbotdevelopment/dbd-tools';\n```\n\nYou can also destructure the package to only import the functions you need:\n\n```js\nconst { getKeys, getValues } = require('@defaultsbotdevelopment/dbd-tools');\n// or\nimport { getKeys, getValues } from '@defaultsbotdevelopment/dbd-tools';\n\n// You can even import all functions as a collection\nconst { ArrayUtils, CacheUtils, ConvertUtils, DiscordUtils, NumberUtils, ObjectUtils, ParseUtils, StringUtils, TimeUtils } = require('@defaultsbotdevelopment/dbd-tools');\n// or\nimport { ArrayUtils, CacheUtils, ConvertUtils, DiscordUtils, NumberUtils, ObjectUtils, ParseUtils, StringUtils, TimeUtils } from '@defaultsbotdevelopment/dbd-tools';\n```\n\n## Functions\n\nThe functions are categorized into the following collections:\n\n- [Array](#array)\n- [Cache](#cache)\n- [Convert](#convert)\n- [Discord](#discord)\n- [Number](#number)\n- [Object](#object)\n- [Parse](#parse)\n- [String](#string)\n- [Time](#time)\n\n### Array\n\nAll available array utility functions.\n\n#### `chunk`\n\nChunks an array into smaller arrays.\n\n```js\nimport { chunk } from '@defaultsbotdevelopment/dbd-tools';\n\nconst array = [1, 2, 3, 4, 5, 6, 7, 8, 9];\n\nconsole.log(chunk(array, 3)); // =\u003e [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n```\n\n#### `hasMatches`\n\nChecks if an array has any matches with another array.\n\n```js\nimport { hasMatches } from '@defaultsbotdevelopment/dbd-tools';\n\nconst array = [1, 2, 3, 4, 5, 6, 7, 8, 9];\nconst array2 = [9, 10, 11];\n\nconsole.log(hasMatches(array, array2)); // =\u003e true\n```\n\n#### `getMatches`\n\nGets all matches from an array.\n\n```js\nimport { getMatches } from '@defaultsbotdevelopment/dbd-tools';\n\nconst array = [1, 2, 3, 4, 5, 6, 7, 8, 9];\nconst array2 = [1, 9, 10, 11];\n\nconsole.log(getMatches(array, array2)); // =\u003e [1, 9]\n```\n\n#### `filterDuplicates`\n\nFilters out duplicate values from an array.\n\n```js\nimport { filterDuplicates } from '@defaultsbotdevelopment/dbd-tools';\n\nconst array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2];\n\nconsole.log(filterDuplicates(array)); // =\u003e [1, 2, 3, 4, 5, 6, 7, 8, 9]\n```\n\n#### `shuffle`\n\nShuffles an array.\n\n```js\nimport { shuffle } from '@defaultsbotdevelopment/dbd-tools';\n\nconst array = [1, 2, 3, 4, 5, 6, 7, 8, 9];\n\nconsole.log(shuffle(array)); // =\u003e [9, 3, 1, 5, 4, 2, 6, 7, 8]\n```\n\n### Cache\n\nAll available cache utility functions.\n\n#### `getCache`\n\nRetrieve JSON data from a cache file in a synchronous manner.\n\n```js\nimport { getCache } from '@defaultsbotdevelopment/dbd-tools';\n\nconst data = getCache('cache.json');\n\nconsole.log(data); // =\u003e { \"key\": \"value\" }\n```\n\n#### `updateCache`\n\nUpdate a cache file with new JSON data in an asynchronous manner.\n\n```js\nimport { updateCache, getCache } from '@defaultsbotdevelopment/dbd-tools';\n\nlet data = getCache('cache.json');\n\ndata.key = 'new value';\n\ndata = await updateCache('cache.json', data);\n\nconsole.log(data); // =\u003e { key: \"new value\" }\n```\n\n### Convert\n\nAll available convert utility functions.\n\n#### `hexToDecimal`\n\nConverts a hexadecimal string to a decimal number.\n\n```js\nimport { hexToDecimal } from '@defaultsbotdevelopment/dbd-tools';\n\nconst hex = '#FFFFFF';\n\nconsole.log(hexToDecimal(hex)); // =\u003e 16777215\n```\n\n#### `toBoolean`\n\nConverts a value to a boolean. Returns `null` if the value cannot be converted.\nThis function accepts a range of values, including strings, numbers, and booleans.\nIt even supports custom strings, which can be passed in the options object. All checks are case-insensitive.\n\n```js\nimport { toBoolean } from '@defaultsbotdevelopment/dbd-tools';\n\nlet options = {\n    boolean: true, // Accept booleans\n    string: true, // Accept strings\n    number: true, // Accept numbers\n    // Custom strings\n    custom:{\n        true: ['yes', 'y', 'ja'],\n        false: ['no', 'n', 'nee']\n    }\n\nconsole.log(toBoolean(true, options)); // =\u003e true\nconsole.log(toBoolean('true', options)); // =\u003e true\nconsole.log(toBoolean(1, options)); // =\u003e true\nconsole.log(toBoolean('yes', options)); // =\u003e true\n\nconsole.log(toBoolean(false, options)); // =\u003e false\nconsole.log(toBoolean('false', options)); // =\u003e false\nconsole.log(toBoolean(0, options)); // =\u003e false\nconsole.log(toBoolean('no', options)); // =\u003e false\n\nconsole.log(toBoolean('maybe', options)); // =\u003e null (not specified as a custom string)\n};\n```\n\n### Discord\n\nAll available Discord utility functions.\n\n#### `formatButtons`\n\nFormats buttons into action rows to be used in a message.\n\n```js\nimport { formatButtons } from '@defaultsbotdevelopment/dbd-tools';\n\nconst buttons = [\n    {\n        button_data...\n    },\n    {\n        button_data...\n    },\n    {\n        button_data...\n    }\n    Twelve more buttons...\n];\n\nconst actionRows = formatButtons(buttons); // =\u003e Returns an array of action rows with buttons\n```\n\n#### `formatSelects`\n\nFormats an array of strings in (multiple) select menus with a max of 25 options per menu.\n\n```js\nimport { formatSelects } from '@defaultsbotdevelopment/dbd-tools';\n\nconst options = [\n    'Option 1',\n    'Option 2',\n    'Option 3',\n    'Option 4',\n    'Option 5',\n    95 more...\n];\n\nconst selectMenus = formatSelects(options); // =\u003e Returns an array of action rows with select menus. Each select menu has a max of 25 options.\n```\n\n#### `getMentions`\n\nGet mentions from a string. Supports users, roles, and channels.\nReturns an object with the following properties: `users`, `roles`, `channels`.\nEach property is an array of IDs.\n\n```js\nimport { getMentions } from '@defaultsbotdevelopment/dbd-tools';\n\nlet options = {\n\tusers: true, // Accept users\n\troles: true, // Accept roles\n\tchannels: true, // Accept channels\n};\n\nconst string = 'Hello world! \u003c@1234567890\u003e \u003c@\u00261234567890\u003e \u003c#1234567890\u003e';\n\nconsole.log(getMentions(string, options)); // =\u003e { users: ['1234567890'], roles: ['1234567890'], channels: ['1234567890'] }\n```\n\n#### Number\n\nAll available number utility functions.\n\n#### `getRandom`\n\nGet a random number between a minimum and maximum value. Both the minimum and maximum value are inclusive.\n\n```js\nimport { getRandom } from '@defaultsbotdevelopment/dbd-tools';\n\nconsole.log(getRandom(1, 10)); // =\u003e 5\n```\n\n### Object\n\nAll available object utility functions.\n\n#### `getValue`\n\nGet a value from an object using a path. The path is a string with keys separated by a dot.\n\n```js\nimport { getValue } from '@defaultsbotdevelopment/dbd-tools';\n\nconst object = {\n\tkey: {\n\t\tkey2: 'value',\n\t},\n};\n\nconsole.log(getValue(object, 'key.key2')); // =\u003e 'value'\n```\n\n#### `setValue`\n\nSet a value in an object using a path. The path is a string with keys separated by a dot.\nIf the path does not exist, it will be created.\n\n```js\nimport { setValue } from '@defaultsbotdevelopment/dbd-tools';\n\nconst object = {\n\tkey: {\n\t\tkey2: 'value',\n\t},\n};\n\nconsole.log(setValue(object, 'key.key3', 'another value')); // =\u003e { key: { key2: 'value', key3: 'another value' } }\n```\n\n#### `hasKey`\n\nCheck if an object has a key. Works with nested objects.\n\n```js\nimport { hasKey } from '@defaultsbotdevelopment/dbd-tools';\n\nconst object = {\n\tkey: {\n\t\tkey2: 'value',\n\t},\n};\n\nconsole.log(hasKey(object, 'key')); // =\u003e true\nconsole.log(hasKey(object, 'key2')); // =\u003e true\n```\n\n#### `hasValue`\n\nCheck if an object has a value. Works with nested objects.\n\n```js\nimport { hasValue } from '@defaultsbotdevelopment/dbd-tools';\n\nconst object = {\n\tkey: {\n\t\tkey2: 'value',\n\t},\n};\n\nconsole.log(hasValue(object, 'value')); // =\u003e true\n```\n\n#### `getKeys`\n\nGet all keys from an object. Returns an array of keys. Works with nested objects.\n\n```js\nimport { getKeys } from '@defaultsbotdevelopment/dbd-tools';\n\nconst object = {\n\tkey: {\n\t\tkey2: 'value',\n\t},\n};\n\nconsole.log(getKeys(object)); // =\u003e ['key', 'key2']\n```\n\n#### `getValues`\n\nGet all values from an object. Returns an array of values. Works with nested objects.\n\n```js\nimport { getValues } from '@defaultsbotdevelopment/dbd-tools';\n\nconst object = {\n\tkey: {\n\t\tkey2: 'value',\n\t},\n};\n\nconsole.log(getValues(object)); // =\u003e ['value']\n```\n\n#### `getEntries`\n\nGet all entries from an object. Returns an array of entries. Works with nested objects.\n\n```js\nimport { getEntries } from '@defaultsbotdevelopment/dbd-tools';\n\nconst object = {\n\tkey: {\n\t\tkey2: 'value',\n\t},\n};\n\nconsole.log(getEntries(object)); // =\u003e [['key', { key2: 'value' }], ['key2', 'value']]\n```\n\n#### `flatten`\n\nFlatten an object. Returns an object with all nested objects flattened.\nOnly the last key of each nested object is kept.\n\n```js\nconst object = {\n\tkey: {\n\t\tkey2: 'value',\n\t},\n};\n\nconsole.log(flatten(object)); // =\u003e { key_key2: 'value' }\n```\n\n### Parse\n\nAll available parse utility functions.\n\n#### `parseEmojis`\n\nParse emojis from a string. Returns all emojis in an array.\nOnly unicode emojis are supported.\n\n```js\nimport { parseEmojis } from '@defaultsbotdevelopment/dbd-tools';\n\nconst string = 'Hello world! 😃';\n\nconsole.log(parseEmojis(string)); // =\u003e ['😃']\n```\n\n#### `parseHexColors`\n\nParse hex colors from a string. Returns all hex colors in an array.\n\n```js\nconst string = 'Hello world! #FFFFFF';\n\nconsole.log(parseHexColors(string)); // =\u003e ['#FFFFFF']\n```\n\n#### `parseRgbColors`\n\nParse RGB colors from a string. Returns all RGB colors in an array.\n\n```js\nconst string = 'Hello world! rgb(255, 255, 255)';\n\nconsole.log(parseRgbColors(string)); // =\u003e ['rgb(255, 255, 255)']\n```\n\n#### `parseHslColors`\n\nParse HSL colors from a string. Returns all HSL colors in an array.\n\n```js\nconst string = 'Hello world! hsl(0, 0%, 100%)';\n\nconsole.log(parseHslColors(string)); // =\u003e ['hsl(0, 0%, 100%)']\n```\n\n#### `parseDecimalColors`\n\nParse decimal colors from a string. Returns all decimal colors in an array.\n\n```js\nconst string = 'Hello world! 16777215';\n\nconsole.log(parseDecimalColors(string)); // =\u003e ['16777215']\n```\n\n### String\n\nAll available string utility functions.\n\n#### `generateUuid`\n\nGenerate a Universally Unique Identifier (UUID).\n\n```js\nimport { generateUuid } from '@defaultsbotdevelopment/dbd-tools';\n\nconsole.log(generateUuid()); // =\u003e 'f4e7a3d0-6b2f-4b1d-8a5c-8d9d9b9b9b9b'\n```\n\n#### `replacer`\n\nReplaces all placeholders in a string with the corresponding values.\n\n```js\nimport { replacer } from '@defaultsbotdevelopment/dbd-tools';\n\nconst string = '{greeting} {user}!';\n\nconst placeholders = {\n\tgreeting: 'Hello',\n\tuser: 'world',\n};\n\nconsole.log(replacer(string, placeholders)); // =\u003e 'Hello world!'\n```\n\n### Time\n\nAll available time utility functions.\n\n#### `msToTimeObject`\n\nConverts milliseconds to an object with the following available properties: `years`, `months`, `weeks`,`days`, `hours`, `minutes`, `seconds`, `milliseconds`.\n\nYou can also specify which properties you want to include in the object. All properties are included by default.\n\n```js\nimport { msToTimeObject } from '@defaultsbotdevelopment/dbd-tools';\n\nconst ms = 1000000000;\n\nconsole.log(msToTimeObject(ms)); // =\u003e { years: 0, months: 0, weeks: 1, days: 4, hours: 13, minutes: 46, seconds: 40 }\n\nconsole.log(msToTimeObject(ms, { seconds: true, minutes: true })); // =\u003e { minutes: 16666, seconds: 40 }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefaultsbotdevelopment%2Fdbd-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdefaultsbotdevelopment%2Fdbd-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefaultsbotdevelopment%2Fdbd-tools/lists"}