{"id":20508095,"url":"https://github.com/appsmithorg/js-utility-library","last_synced_at":"2026-05-29T12:31:44.938Z","repository":{"id":194592847,"uuid":"691164061","full_name":"appsmithorg/js-utility-library","owner":"appsmithorg","description":"Javascript Utility Library","archived":false,"fork":false,"pushed_at":"2024-08-30T19:54:51.000Z","size":5048,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-12T22:35:02.216Z","etag":null,"topics":[],"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/appsmithorg.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}},"created_at":"2023-09-13T16:16:35.000Z","updated_at":"2023-09-27T09:30:38.000Z","dependencies_parsed_at":"2023-09-14T07:43:51.971Z","dependency_job_id":"f73d5c8b-6f48-4733-96a7-45b14db71e62","html_url":"https://github.com/appsmithorg/js-utility-library","commit_stats":null,"previous_names":["appsmithorg/app-utils-library"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/appsmithorg/js-utility-library","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appsmithorg%2Fjs-utility-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appsmithorg%2Fjs-utility-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appsmithorg%2Fjs-utility-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appsmithorg%2Fjs-utility-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appsmithorg","download_url":"https://codeload.github.com/appsmithorg/js-utility-library/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appsmithorg%2Fjs-utility-library/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33652979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-15T20:16:55.652Z","updated_at":"2026-05-29T12:31:44.922Z","avatar_url":"https://github.com/appsmithorg.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.appsmith.com?utm_source=github\u0026utm_medium=organic\u0026utm_campaign=readme\"\u003e\n  \u003cimg src=\"static/appsmith_logo_white.png\" alt=\"Appsmith Logo\" width=\"350\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n# Appsmith Utility Library Module\n\nThis is a collection of utility functions for common tasks in JavaScript. This module includes functions to work with arrays, objects, and generate unique IDs. It's designed to be simple to use and can be easily integrated into your Node.js, browser-based projects or Appsmith apps.\n\n## Installation\n\nYou can install Appsmith Utility Library using npm:\n\n```bash\nnpm install git@github.com:appsmithorg/js-utility-library.git\n```\n\nor JsDelivr\n\n```bash\nhttps://cdn.jsdelivr.net/gh/appsmithorg/js-utility-library/dist/index.min.js\n```\n\n## Usage\n\nHere are the functions available in this module and how to use them:\n\n## `getUniqueValues(data, field)`\n\nGet unique values from an array of objects based on a specified field.\n\n```javascript\nconst utils = require('@appsmith/js-utility-library');\n\nlet array = [\n  {\n    name: 'fox',\n    type: 'animal',\n  },\n  {\n    name: 'table',\n    type: 'object',\n  },\n  {\n    name: 'chair',\n    type: 'object',\n  },\n  // More objects...\n];\n\nlet uniqueTypes = utils.getUniqueValues(array, 'type');\nconsole.log(uniqueTypes); // Output: ['animal', 'object', ...]\n```\n\n## `generateId(type, length = 10)`\n\nGenerate a unique ID of the specified type ('random' or 'uuid').\n\n```javascript\nconst utils = require('@appsmith/js-utility-library');\n\nlet randomId = utils.generateId('random', 8);\nconsole.log(randomId); // Output: A random 8-character string\n\nlet uuid = utils.generateId('uuid');\nconsole.log(uuid); // Output: A UUID (Universally Unique Identifier)\n```\n\n## `filterQueryFactoryPostgres(filters)`\n\nThe `filterQueryFactoryPostgres` function is a utility function for generating SQL query conditions based on an array of filters. It is particularly useful when working with PostgreSQL databases.\n\n### Parameters\n\n- `filters` (Array of Objects): An array of filter objects, where each object defines a filtering condition. Each filter object should have the following properties:\n  - `column` (String): The name of the database column you want to filter on.\n  - `condition` (String): The filtering condition to apply (e.g., 'isEqualTo', 'lessThan', 'contains', etc.).\n  - `value` (String or Number): The value to compare against in the filtering condition.\n  - `operator` (String, optional): The logical operator ('AND' or 'OR') to use when combining multiple filters. The default is 'WHERE' for the first filter and 'AND' for subsequent ones.\n\n### Example\n\nHere's an example of how to use the `filterQueryFactoryPostgres` function to generate SQL query conditions:\n\n```javascript\nconst utils = require('@appsmith/js-utility-library');\n\nconst filters = [\n  {\n    id: 't52x5q7nwc',\n    operator: 'or',\n    column: 'id',\n    condition: 'greaterthan',\n    value: 2,\n  },\n  {\n    id: '9ke2d1hjqo',\n    operator: 'and',\n    column: 'logo_url',\n    condition: 'notempty',\n    value: '',\n  },\n];\n\nconst sqlConditions = utils.filterQueryFactoryPostgres(filters);\n\nconsole.log(sqlConditions);\n// Output: \"WHERE id \u003e 2 AND logo_url IS NOT NULL\"\n```\n\n## `filterQueryFactoryMongo(filters)`\n\nThe `filterQueryFactoryMongo` function is a utility function for generating MongoDB query conditions based on an array of filters. It is particularly useful when working with MongoDB databases.\n\n### Parameters\n\n- `filters` (Array of Objects): An array of filter objects, where each object defines a filtering condition. Each filter object should have the following properties:\n  - `column` (String): The name of the MongoDB field you want to filter on.\n  - `condition` (String): The filtering condition to apply (e.g., 'isEqualTo', 'lessThan', 'contains', etc.).\n  - `value` (String or Number): The value to compare against in the filtering condition.\n  - `operator` (String, optional): The logical operator ('AND' or 'OR') to use when combining multiple filters. The default is 'WHERE' for the first filter and 'AND' for subsequent ones.\n\n### Example\n\nHere's an example of how to use the `filterQueryFactoryMongo` function to generate MongoDB query conditions:\n\n```javascript\nconst utils = require('@appsmith/js-utility-library');\n\nconst filters = [\n  {\n    id: 'yq04iff2ao',\n    operator: 'OR',\n    column: 'rating',\n    condition: 'greaterThan',\n    value: 2,\n  },\n  {\n    id: '1fn49sn0w5',\n    operator: 'AND',\n    column: 'total_cost',\n    condition: 'greaterThan',\n    value: 10000,\n  },\n];\n\nconst mongoQuery = utils.queryFactoryMongo(filters);\n\nconsole.log(mongoQuery);\n// Output: {\n//  \"$and\": [\n//    {\n//      \"rating\": {\n//        \"$gt\": 2\n//      }\n//    },\n//    {\n//      \"total_cost\": {\n//        \"$gt\": 10000\n//      }\n//    }\n//  ]\n// }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappsmithorg%2Fjs-utility-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappsmithorg%2Fjs-utility-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappsmithorg%2Fjs-utility-library/lists"}