{"id":15102064,"url":"https://github.com/probir-sarkar/one-liner-js","last_synced_at":"2026-03-07T11:03:19.843Z","repository":{"id":240051555,"uuid":"801534922","full_name":"probir-sarkar/one-liner-js","owner":"probir-sarkar","description":"One-Liner JavaScript: A collection of one-liner JavaScript snippets for your next project","archived":false,"fork":false,"pushed_at":"2024-08-25T10:11:25.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-22T22:37:01.250Z","etag":null,"topics":["deno","freshjs","preactjs"],"latest_commit_sha":null,"homepage":"https://one-liner-js.deno.dev/","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/probir-sarkar.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-16T12:21:09.000Z","updated_at":"2024-08-25T10:11:27.000Z","dependencies_parsed_at":"2024-08-25T10:46:37.687Z","dependency_job_id":"2a59006f-9838-433a-9772-244011f6b4eb","html_url":"https://github.com/probir-sarkar/one-liner-js","commit_stats":null,"previous_names":["probir-sarkar/one-liner-code","probir-sarkar/one-liner-js"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/probir-sarkar/one-liner-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probir-sarkar%2Fone-liner-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probir-sarkar%2Fone-liner-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probir-sarkar%2Fone-liner-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probir-sarkar%2Fone-liner-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/probir-sarkar","download_url":"https://codeload.github.com/probir-sarkar/one-liner-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probir-sarkar%2Fone-liner-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30212103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T09:02:10.694Z","status":"ssl_error","status_checked_at":"2026-03-07T09:02:08.429Z","response_time":53,"last_error":"SSL_read: 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":["deno","freshjs","preactjs"],"created_at":"2024-09-25T18:45:56.132Z","updated_at":"2026-03-07T11:03:19.816Z","avatar_url":"https://github.com/probir-sarkar.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# One-Liner JavaScript Snippets\r\n\r\nA collection of useful one-liner JavaScript snippets for your next project.\r\n\r\n### 1. Capitalize Text\r\n\r\n```javascript\r\nconst capitalize = (str) =\u003e `${str.charAt(0).toUpperCase()}${str.slice(1)}`;\r\n```\r\n\r\n**Description:** The `capitalize` function takes a string as input and returns a new string with the first character converted to uppercase while leaving the rest of the string unchanged.\r\n\r\n### 2. Calculate Percent\r\n\r\n```javascript\r\nconst calculatePercent = (value, total) =\u003e Math.round((value / total) * 100);\r\n```\r\n\r\n**Description:** Calculates the percentage of `value` relative to `total`, rounded to the nearest integer. It includes error handling for non-numeric inputs and checks for a zero total to prevent division by zero.\r\n\r\n### 3. Get a Random Element\r\n\r\n```javascript\r\nconst getRandomItem = (items) =\u003e items[Math.floor(Math.random() * items.length)];\r\n```\r\n\r\n**Description:** Returns a random element from an array.\r\n\r\n### 4. Check if a String is a Palindrome\r\n\r\n```javascript\r\nconst isPalindrome = (str) =\u003e str === str.split(\"\").reverse().join(\"\");\r\n```\r\n\r\n**Description:** Checks if a given string is a palindrome (reads the same backward as forward).\r\n\r\n### 5. Reverse a String\r\n\r\n```javascript\r\nconst reversedString = (str) =\u003e str.split(\"\").reverse().join(\"\");\r\n```\r\n\r\n**Description:** Reverses the characters in a string.\r\n\r\n### 6. Shuffle an Array\r\n\r\n```javascript\r\nconst shuffleArray = (arr) =\u003e arr.sort(() =\u003e 0.5 - Math.random());\r\n```\r\n\r\n**Description:** Randomly shuffles the elements of an array.\r\n\r\n### 7. Check if a Number is Even\r\n\r\n```javascript\r\nconst isEven = (num) =\u003e num % 2 === 0;\r\n```\r\n\r\n**Description:** Returns `true` if the number is even, `false` otherwise.\r\n\r\n### 8. Get the Length of an Object\r\n\r\n```javascript\r\nconst objectLength = (obj) =\u003e Object.keys(obj).length;\r\n```\r\n\r\n**Description:** Returns the number of properties in an object.\r\n\r\n### 9. Deep Clone an Object (Simple Implementation)\r\n\r\n```javascript\r\nconst deepClone = (obj) =\u003e JSON.parse(JSON.stringify(obj));\r\n```\r\n\r\n**Description:** Creates a deep clone of an object. This method is simple but may not work for objects with functions or undefined values.\r\n\r\n### 10. Convert a Number to a Boolean (Truthy or Falsy)\r\n\r\n```javascript\r\nconst isTruthy = (num) =\u003e !!num;\r\n```\r\n\r\n**Description:** Converts a number to its boolean equivalent (truthy or falsy).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprobir-sarkar%2Fone-liner-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprobir-sarkar%2Fone-liner-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprobir-sarkar%2Fone-liner-js/lists"}