{"id":22725108,"url":"https://github.com/katmore/flat-js","last_synced_at":"2025-07-29T09:35:15.554Z","repository":{"id":58240669,"uuid":"69918499","full_name":"katmore/flat-js","owner":"katmore","description":"The Flat Javascript Companion","archived":false,"fork":false,"pushed_at":"2019-04-18T21:17:20.000Z","size":100,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-30T01:04:38.468Z","etag":null,"topics":["javascript","javascript-library"],"latest_commit_sha":null,"homepage":"","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/katmore.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}},"created_at":"2016-10-03T23:10:39.000Z","updated_at":"2020-02-26T13:55:16.000Z","dependencies_parsed_at":"2022-08-31T00:22:31.583Z","dependency_job_id":null,"html_url":"https://github.com/katmore/flat-js","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/katmore/flat-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katmore%2Fflat-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katmore%2Fflat-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katmore%2Fflat-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katmore%2Fflat-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/katmore","download_url":"https://codeload.github.com/katmore/flat-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katmore%2Fflat-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267663063,"owners_count":24123993,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"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":["javascript","javascript-library"],"created_at":"2024-12-10T15:08:51.823Z","updated_at":"2025-07-29T09:35:15.502Z","avatar_url":"https://github.com/katmore.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flat-js\r\n**The Flat JavaScript Companion**\r\n\r\n*Flat-js* contains convenience wrappers and utility functions.\r\n\r\n## Installation\r\n*Flat-js* may be installed using Bower or a CDN as described below.\r\n\r\n### Install using Bower\r\n#### Bower Step 1: execute bower shell command:\r\n```Shell\r\n$ bower install flat-js --save\r\n```\r\n#### Bower Step 2: include script tag pointing your project's bower components path\r\n```html\r\n\u003c!-- change './bower_components' to point to your project's bower components path as appropriate--\u003e\r\n\u003cscript src=\"./bower_components/flat-js/dist/js/flat.min.js\"\u003e\u003c/script\u003e\r\n```\r\n\r\n### Install using CDN\r\n**Include script tag from githack CDN:**\r\n```html\r\n\u003cscript src=\"https://rawcdn.githack.com/katmore/flat-js/master/src/js/flat.js\"\u003e\u003c/script\u003e\r\n```\r\n(See the [githack CDN FAQ](https://raw.githack.com/#faq) for more information)\r\n\r\n## Examples\r\n * [URL query examples](#url-query-examples)\r\n * [Value testing examples](#value-testing-examples)\r\n * [Heredoc examples](#heredoc-examples)\r\n\r\n### URL query examples\r\n*Flat-js* simplifies reading and manipulating browser URLs to a single line of code.\r\n\r\nIn the examples below, replace \"example.com\" with the host and path to your project/resource, \r\nthen add the query string to the URL in your browser.\r\n\r\n#### Determine if a url query key exists.\r\n* source:\r\n```js\r\n//\r\n// assuming browser URL: http://example.com/?ohai\u0026my_key=my_value\r\n//\r\nvar ohai_exists = flat.urlQueryExists('ohai');\r\nvar obai_exists = flat.urlQueryExists('obai');\r\nvar mykey_exists = flat.urlQueryExists('obai');\r\nconsole.log('Does \"ohai\" exist? '+ohai_exists);\r\nconsole.log('Does \"obai\" exist? '+obai_exists);\r\nconsole.log('Does \"my_key\" exist? ' + mykey_exists);\r\n```\r\n* console output:\r\n```txt\r\nDoes \"ohai\" exist? true\r\nDoes \"obai\" exist? false\r\nDoes \"my_key\" exist? true\r\n```\r\n#### Get a url query key value.\r\n* source:\r\n```js\r\n//\r\n// assuming browser URL: http://example.com/?my_key=my_value\r\n//\r\nvar myKeyValue = flat.urlQueryGet('my_key');\r\nconsole.log('my_key value: '+ myKeyValue);\r\n```\r\n* console output:\r\n```txt\r\nmy_key value: my_value\r\n```\r\n#### Determine if a url query key has a \"truthy\" value.\r\n* source:\r\n```javascript\r\n//\r\n// assuming browser URL: \r\n//   http://example.com/?my_option1=on,my_option2=off,my_option3=yes,my_option4=no,my_option5=true,my_option6=false\r\n//\r\nvar myOption1 = flat.urlQueryTruthy('my_option1');\r\nvar myOption2 = flat.urlQueryTruthy('my_option2');\r\nvar myOption3 = flat.urlQueryTruthy('my_option3');\r\nvar myOption4 = flat.urlQueryTruthy('my_option4');\r\nvar myOption5 = flat.urlQueryTruthy('my_option5');\r\nvar myOption6 = flat.urlQueryTruthy('my_option6');\r\nconsole.log('myOption1: '+myOption1 + ' (string value was \"on\")');\r\nconsole.log('myOption2: '+myOption2 + ' (string value was \"off\")');\r\nconsole.log('myOption3: '+myOption3 + ' (string value was \"yes\")');\r\nconsole.log('myOption4: '+myOption4 + ' (string value was \"no\")');\r\nconsole.log('myOption5: '+myOption5 + ' (string value was \"true\")');\r\nconsole.log('myOption6: '+myOption6 + ' (string value was \"false\")');\r\n```\r\n* console output:\r\n```txt\r\nmyOption1: true (string value was \"on\")\r\nmyOption2: false (string value was \"off\")\r\nmyOption3: true (string value was \"yes\")\r\nmyOption4: false (string value was \"no\")\r\nmyOption5: true (string value was \"true\")\r\nmyOption6: false (string value was \"false\")\r\n```\r\n#### Change a url query value.\r\n* source:\r\n```js\r\n//\r\n// assuming browser URL: http://example.com/?my_key=my_value\r\n//\r\nflat.urlQuerySet('my_key','my_new_value');\r\n//\r\n// look at your browser URL now, \r\n//    it will read: http://example.com/?my_key=my_new_value\r\n//\r\nconsole.log('my_key value: '+ flat.urlQueryGet('my_key'));\r\n```\r\n* console output:\r\n```txt\r\nmy_key value: my_new_value\r\n```\r\n\r\n### Value testing examples\r\n*Flat-js* simplifies many value tests to a single line of code.\r\n\r\n#### Determine if value is function\r\n* source:\r\n```javascript\r\nvar var1 = function() {};\r\nvar var2 = {};\r\nvar var3 = \"\";\r\nvar var4 = 1;\r\nvar var5 = [];\r\nvar isVar1Function = flat.isFunc(var1);\r\nvar isVar2Function = flat.isFunc(var2);\r\nvar isVar3Function = flat.isFunc(var3);\r\nvar isVar4Function = flat.isFunc(var4);\r\nvar isVar5Function = flat.isFunc(var5);\r\nconsole.log('is var1 a function? '+isVar1Function);\r\nconsole.log('is var2 a function? '+isVar2Function);\r\nconsole.log('is var3 a function? '+isVar3Function);\r\nconsole.log('is var4 a function? '+isVar4Function);\r\nconsole.log('is var5 a function? '+isVar5Function);\r\n```\r\n* console output:\r\n```txt\r\nis var1 a function? true\r\nis var2 a function? false\r\nis var3 a function? false\r\nis var4 a function? false\r\nis var5 a function? false\r\n```\r\n#### Determine if value is integer\r\n* source:\r\n```js\r\nvar var1 = function() {};\r\nvar var2 = {};\r\nvar var3 = \"\";\r\nvar var4 = 1;\r\nvar var5 = [];\r\nvar isVar1Integer = flat.isInt(var1);\r\nvar isVar2Integer = flat.isInt(var2);\r\nvar isVar3Integer = flat.isInt(var3);\r\nvar isVar4Integer = flat.isInt(var4);\r\nvar isVar5Integer = flat.isInt(var5);\r\nconsole.log('is var1 a integer? '+isVar1Integer);\r\nconsole.log('is var2 a integer? '+isVar2Integer);\r\nconsole.log('is var3 a integer? '+isVar3Integer);\r\nconsole.log('is var4 a integer? '+isVar4Integer);\r\nconsole.log('is var5 a integer? '+isVar5Integer);\r\n```\r\n* console output:\r\n```txt\r\nis var1 a integer? false\r\nis var2 a integer? false\r\nis var3 a integer? false\r\nis var4 a integer? true\r\nis var5 a integer? false\r\n```\r\n#### Determine if value is string\r\n* source:\r\n```js\r\nvar var1 = function() {};\r\nvar var2 = {};\r\nvar var3 = \"\";\r\nvar var4 = 1;\r\nvar var5 = [];\r\nvar isVar1String = flat.isString(var1);\r\nvar isVar2String = flat.isString(var2);\r\nvar isVar3String = flat.isString(var3);\r\nvar isVar4String = flat.isString(var4);\r\nvar isVar5String = flat.isString(var5);\r\n```\r\n* console output:\r\n```txt\r\nis var1 a string? false\r\nis var2 a string? false\r\nis var3 a string? true\r\nis var4 a string? false\r\nis var5 a string? false\r\n```\r\n#### Determine if value is array or object\r\nflat.isArray() and flat.isObject() work similarly to flat.isFunc(), flat.isInt, and flat.isString()...\r\n* source:\r\n```js\r\nvar var1 = function() {};\r\nvar var2 = {};\r\nvar var3 = \"\";\r\nvar var4 = 1;\r\nvar var5 = [];\r\nconsole.log('is var1 an array: '+flat.isArray(var1));\r\nconsole.log('is var1 an object: '+flat.isObject(var1));\r\nconsole.log('is var2 an array: '+flat.isArray(var2));\r\nconsole.log('is var2 an object: '+flat.isObject(var2));\r\nconsole.log('is var3 an array: '+flat.isArray(var3));\r\nconsole.log('is var3 an object: '+flat.isObject(var3));\r\nconsole.log('is var4 an array: '+flat.isArray(var4));\r\nconsole.log('is var4 an object: '+flat.isObject(var4));\r\nconsole.log('is var5 an array: '+flat.isArray(var5));\r\nconsole.log('is var5 an object: '+flat.isObject(var5));\r\n```\r\n* console output:\r\n```txt\r\nis var1 an array: false\r\nis var1 an object: false\r\nis var2 an array: false\r\nis var2 an object: true\r\nis var3 an array: false\r\nis var3 an object: false\r\nis var4 an array: false\r\nis var4 an object: false\r\nis var5 an array: true\r\nis var5 an object: false\r\n```\r\n### Heredoc examples\r\nThe `flat.heredoc()` function facilitates a HEREDOC-like declaration of string values.\r\n\r\n#### single-line heredoc string declaration\r\n* source:\r\n```js\r\nvar myString = flat.heredoc(function() { /*this is the string value*/ });\r\nconsole.log(myString);\r\n```\r\n* console output:\r\n```txt\r\nthis is the string value\r\n```\r\n     \r\n#### multi-line heredoc string declaration\r\n* source:\r\n```js\r\nvar myString = flat.heredoc(function() { /*\r\nthis string has\r\nmore than\r\none line\r\n*/ });\r\nconsole.log(myString);\r\n```\r\n* console output:\r\n```txt\r\nthis string has\r\nmore than\r\none line\r\n```\r\n\r\n## Legal\r\n### Copyright\r\nThe Flat JavaScript Companion - https://github.com/katmore/flat-js\r\n\r\nCopyright (c) 2012-2019 Garrison Koch, Doug Bird, and Daniel Lepthien. All Rights Reserved.\r\n\r\n### License\r\n\"The Flat JavaScript Companion\" is copyrighted free software.\r\n\r\nYou may redistribute and modify it under either the terms and conditions of the\r\n\"The MIT License (MIT)\"; or the terms and conditions of the \"GPL v3 License\".\r\nSee [LICENSE](https://github.com/katmore/flat-js/blob/master/LICENSE) and [GPLv3](https://github.com/katmore/flat-js/blob/master/GPLv3).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatmore%2Fflat-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatmore%2Fflat-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatmore%2Fflat-js/lists"}