{"id":17036021,"url":"https://github.com/phucbm/os-util","last_synced_at":"2026-03-17T11:03:31.927Z","repository":{"id":184406545,"uuid":"663434031","full_name":"phucbm/os-util","owner":"phucbm","description":"Utility functions for open-source projects.","archived":false,"fork":false,"pushed_at":"2023-09-29T03:20:42.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-17T10:22:36.583Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/phucbm.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-07-07T09:28:34.000Z","updated_at":"2023-07-28T07:51:45.000Z","dependencies_parsed_at":"2024-11-29T22:18:18.435Z","dependency_job_id":null,"html_url":"https://github.com/phucbm/os-util","commit_stats":null,"previous_names":["phucbm/os-util"],"tags_count":1,"template":false,"template_full_name":"phucbm/js-webpack-boilerplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fos-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fos-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fos-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fos-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phucbm","download_url":"https://codeload.github.com/phucbm/os-util/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245031345,"owners_count":20549913,"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":[],"created_at":"2024-10-14T08:48:57.494Z","updated_at":"2025-10-29T15:16:30.659Z","avatar_url":"https://github.com/phucbm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OS Util\n\n[![npm version](https://badgen.net/npm/v/@phucbm/os-util?icon=npm)](https://www.npmjs.com/package/@phucbm/os-util)\n[![npm downloads](https://badgen.net/npm/dm/@phucbm/os-util?icon=npm)](https://www.npmjs.com/package/@phucbm/os-util)\n[![npm dependents](https://badgen.net/npm/dependents/@phucbm/os-util?icon=npm)](https://www.npmjs.com/package/@phucbm/os-util)\n[![github stars](https://badgen.net/github/stars/phucbm/os-util?icon=github)](https://github.com/phucbm/os-util/)\n[![jsdelivr npm rank](https://badgen.net/jsdelivr/rank/npm/@phucbm/os-util?icon=npm)](https://www.npmjs.com/package/@phucbm/os-util)\n[![github license](https://badgen.net/github/license/phucbm/os-util?icon=github)](https://github.com/phucbm/os-util/blob/main/LICENSE)\n[![Made in Vietnam](https://raw.githubusercontent.com/webuild-community/badge/master/svg/made.svg)](https://webuild.community)\n\nhttps://www.npmjs.com/package/@phucbm/os-util\n\n## Install\n\n```shell\n# Install\nnpm i @phucbm/os-util\n```\n\n## Features\n\n### Get options from attribute\n\n```js\nimport {getOptionsFromAttribute} from \"@phucbm/os-util\";\n```\n\n#### 1. Test cases for boolean and numeric values\n\n```html\n\n\u003csection data-json='{\"testNum\":\"480\", \"testFalse\":\"false\", \"testTrue\":\"true\"}'\u003e\n\u003c/section\u003e\n```\n\n```js\nconst options = getOptionsFromAttribute({\n    target: document.querySelector('section'), // required, DOM element that holds the attribute\n    attributeName: 'data-json', // required, attribute name that holds the value\n    numericValues: ['testNum'], // optional, the props will be converted into numeric values\n    defaultOptions: {}, // optional, options from attribute will override these default options, \n    // or return defaultOptions if options are not found\n});\nconsole.log(options); // =\u003e {\"testNum\": 480, \"testFalse\": false, \"testTrue\": true};\n```\n\n#### 2. Empty value\n\n```html\n\n\u003csection data-json\u003e\u003c/section\u003e\n```\n\n```js\nconst options = getOptionsFromAttribute({\n    target: document.querySelector('section'),\n    attributeName: 'data-json',\n});\nconsole.log(options); // =\u003e {}\n```\n\n#### 3. Value is just a string\n\n```html\n\n\u003csection data-json=\"hello-world\"\u003e\u003c/section\u003e\n```\n\n```js\nconst options = getOptionsFromAttribute({\n    target: document.querySelector('section'),\n    attributeName: 'data-json',\n    onIsString: value =\u003e {\n        console.log(value); // =\u003e \"hello-world\"\n    }\n});\nconsole.log(options); // =\u003e {}\n```\n\n### Events Manager\n\n```js\nimport {EventsManager} from \"@phucbm/os-util\";\n```\n\nIn your plugin constructor\n\n```js\n// init events manager\nthis.events = new EventsManager(this, {\n    names: ['onInit'] // register event names\n});\n\n// fire an event\nthis.events.fire('onInit', {source}); // the 2nd param is an object that will be passed to the callback\n```\n\nCreate a method to assign late-events\n\n```js\n/**\n * Assign late-events\n */\nfunction on(eventName, callback){\n    this.events.add(eventName, callback);\n}\n```\n\nUsage\n\n```js\n// add event from init\nconst instance = Plugin.init({\n    onInit: data =\u003e {\n        console.log('init', data)\n    }\n});\n\n// add via method after init\ninstance.on('onInit', data =\u003e {\n    console.log('init', data)\n});\n\n// with or without keyword on before the event name are all acceptable\ninstance.on('init', data =\u003e {\n    console.log('init', data)\n});\n```\n\n## Deployment\n\n```shell\n# Publish package\n# 1. Export the new function in index.js\n# 2. Update version in package.json\n# 3. Run publish\nnpm publish\n\n# Dev\nnpm run dev\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucbm%2Fos-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphucbm%2Fos-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucbm%2Fos-util/lists"}