{"id":25300141,"url":"https://github.com/deftio/simplejslib","last_synced_at":"2026-04-29T00:34:45.665Z","repository":{"id":148290331,"uuid":"201531243","full_name":"deftio/simpleJSLib","owner":"deftio","description":"Simple Javascript library example which runs in browser / nodejs / commonjs and AMD environments.  This library not require a build tool.","archived":false,"fork":false,"pushed_at":"2022-12-31T03:51:52.000Z","size":249,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T23:41:21.403Z","etag":null,"topics":["amd","commonjs","es6","es6-modules","javascript","javascript-library","nodejs","umd","universal-javascript"],"latest_commit_sha":null,"homepage":"https://deftio.github.io/simpleJSLib","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deftio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2019-08-09T19:48:37.000Z","updated_at":"2023-03-21T02:56:54.000Z","dependencies_parsed_at":"2023-05-19T15:45:25.452Z","dependency_job_id":null,"html_url":"https://github.com/deftio/simpleJSLib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/deftio/simpleJSLib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deftio%2FsimpleJSLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deftio%2FsimpleJSLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deftio%2FsimpleJSLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deftio%2FsimpleJSLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deftio","download_url":"https://codeload.github.com/deftio/simpleJSLib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deftio%2FsimpleJSLib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32405901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"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":["amd","commonjs","es6","es6-modules","javascript","javascript-library","nodejs","umd","universal-javascript"],"created_at":"2025-02-13T05:38:32.001Z","updated_at":"2026-04-29T00:34:45.660Z","avatar_url":"https://github.com/deftio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Simple JS Lib: A Javascript library working example based on the UMD (Universal Module Defition) with ES6 import support.\n\nThis repo contains a working example of a simple \"universal\" javascript library which exports correctly on commonjs (nodejs), requirejs, and web-browser environments without need for a build/packing tool.  This allows properly written js code to work in both browser and console apps.\n\nUseful for quick n dirty jobs. Based on the UMD univeral module definition.\n\n## Usage\n\nUsing the file simpleJSlib.js as a template define your module here:\n\n```javascript\n//see simpleJSlib.js in this repo\n\n(function (root, factory) {\n\n    if (typeof define === 'function' \u0026\u0026 define.amd) {\n        // AMD. Register as an anonymous module.\n        //console.log(\"AMD\") \n        define([], factory);\n    } else if (typeof exports === 'object') {\n        \n        if ((typeof module !== 'object' ) || (typeof module !== \"function\") ) // this hack required for older versions of node\n            var m =require('module');\n        // Node. Does not work with strict CommonJS, but\n        // only CommonJS-like environments that support module.exports, like Node.\n        //console.log(\" CommonJS ...\");\n        var lib= factory();\n        module.exports=lib;\n\n    } else {\n        //console.log(\"browser..\",root, typeof root);\n        // Browser globals (root is window)\n        var lib = factory();\n        root[lib[\"exportName\"]] = lib;\n  }\n//end of \"boilerplate\" ====== below is where the real library code is written\n}(typeof self !== 'undefined' ? self : this, function ( /* dependancies go here, eg. lib1, $, ... ,  */) {\n    \"use strict\";\n    \n    var myLibraryCode = {};  \n    myLibraryCode.exportName = \"myModule\"; // this is the name you give to your library in browser apps.  In nodejs this is not relavant.\n\n    // YOUR LIBRARY CODE HERE \n    myLibraryCode.a = function(){return \"a\"};\n    myLibraryCode.b = function(){return \"b\"};\n    myLibraryCode.simpleMethod = function(){return \"simpleMethod called\"};\n    \n    myLibraryCode.simplePropArray = [1,2,3,4,5];\n\n    // return your module\n    return myLibraryCode;\n}));\n\n```\n\nNow in the browser simply include a tag like this:\n```HTML\n\n\u003cscript src=\"./simpleJSlib.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n//use your library with the name you gave in in the export name line...\nmyModule.simpleMethod()  // calls function simpleMethod in myModule\n\u003c/script\u003e\n```\n\nAnd in nodejs do this (using built-in require)\n```javascript\n\nvar x = require (\"./simpleJSlib.js\"); //this is to assign your module to the var x for usage in node\nx.simpleMethod();  // calls simpleMethod in your node js code\n\n```\n\nAnd if using AMD style definitions (see [requirejs.org](requirejs.org) ) use this\n```javascript\n\nvar requirejs = require(\"./path/to/requirejs/r.js\"); // this is to load the AMD style loader from requirejs (see requirejs.org)\n\nrequirejs.config({\n    //Pass the top-level main.js/index.js require\n    //function to requirejs so that node modules\n    //are loaded relative to the top-level JS file.\n    nodeRequire: require\n});\n\nrequirejs ([\"path/to/your/library/simpleJSlib.js\"]); // note jsumd is just what the example is named here.  It should be whatever your actual library is called.\n\nvar x=requirejs(\"simpleJSLib\"); // requirejs uses the filename given above as the object name \n\nx.simpleMethod();  // calls simpleMethod\n```\n\n### Testing\n\nIn the repo are 4 crude tests:\n```\numdtest.html        - a simple web page loading the example module - just load in any browser \nnode-cjs-test.js    - a simple nodejs app using built-in require (commonjs format)\nnode-amd-test.js    - a simple console nodejs app using AMD style requirejs loading\n```\n\nto use the nodejs tests either type your local invocation of node such as:\n\n```\nnode node-cjs-test.js\n```\n\nor on POSIX systems you can just run them directly (assuming nodejs is installed)\n\n```\n./node-cjs-test.js   // this uses the built-in shebang \n```\n\n### ES Module Support\nthe Javascript ES6 module format came after the UMD, AMD and require convetions.  It allows one to create reusable code that can be tree-shaken (means redundant or unused code is removed in most applications).\n\nTo support building a library with ES support a package generator such as rollup or webpack is receommended. However we can convert our simple library to module format by using putting our code in the format as shown in [./ES_import_support](ES_import_support).\n\nHere a simple tool copies our code from our UMD code and exports as a default export for use with javascript import support.\n\nTo do this run the command line too in the folder:\n```javscript\n./umd2ModuleHack.js\n```\nIt will cut out the code in the library and export it as importable module.  Note this is not the ideal way to create a module but it does allow a quick port of old UMD style projects.\n\nFor this to work a package.json informing node.js to support imports as modules is needed.\n\n\n### NPM and Publshing\nIf you wish to make your library available to the NPM universe, install npm and the follow these commands.\n\n```shell\nnpm init\n```\n\nnpm will prompt you for several items and create a package.json file.  Once this is complete you can add dependancies using npm commands.  If you do plan on publising your libray be sure to check to make sure you have chosen a unique name in the npm universe.  You can search it as [npmjs](https://www.npmjs.com/).\n\nNow when you are all ready to publish it just use this command and npm will push it to the npm servers and host it.\n\n```shell\nnpm publish\n```\n\n### CDN\nnpm also provides a free CDN (Content Delivery Network) so you can use your new library.  You can reade more about it here: [unpkg](https://unpkg.com).  \n\nJust including the name like this in your HTML code:\n\n```html\n\u003cscript src=\"https://unpkg.com/your-library-name\"\u003e\u003c/src\u003e\n```\n\n\n### Why?\n\nHad issues with finding simple examples for basic bare-bones js library defitions.   This example should work without any reliance on a larger build framework/packer for quick testing.\n\nGoog luck \u0026 feedback welcome\n\n-Manu\n\n### License yada yada\n\nBSD 2.0 License (see file in repo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeftio%2Fsimplejslib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeftio%2Fsimplejslib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeftio%2Fsimplejslib/lists"}