{"id":16203960,"url":"https://github.com/mottie/join-non-empty-array","last_synced_at":"2025-04-07T19:41:38.171Z","repository":{"id":57281460,"uuid":"142936902","full_name":"Mottie/join-non-empty-array","owner":"Mottie","description":"Join non-empty array elements into a string","archived":false,"fork":false,"pushed_at":"2019-10-27T22:43:36.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-14T02:03:37.386Z","etag":null,"topics":["array","join","node","string"],"latest_commit_sha":null,"homepage":"https://npm.im/join-non-empty-array","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/Mottie.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":"2018-07-30T23:07:40.000Z","updated_at":"2020-01-12T09:58:49.000Z","dependencies_parsed_at":"2022-09-19T22:01:38.036Z","dependency_job_id":null,"html_url":"https://github.com/Mottie/join-non-empty-array","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mottie%2Fjoin-non-empty-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mottie%2Fjoin-non-empty-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mottie%2Fjoin-non-empty-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mottie%2Fjoin-non-empty-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mottie","download_url":"https://codeload.github.com/Mottie/join-non-empty-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247719853,"owners_count":20984849,"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":["array","join","node","string"],"created_at":"2024-10-10T09:55:49.004Z","updated_at":"2025-04-07T19:41:38.154Z","avatar_url":"https://github.com/Mottie.png","language":"JavaScript","readme":"# join-non-empty-array  [![Build Status](https://travis-ci.org/Mottie/join-non-empty-array.svg?branch=master)](https://travis-ci.org/Mottie/join-non-empty-array)\n\n\u003e Join non-empty array elements into a string\n\n## Install\n\n```bash\n$ npm install --save join-non-empty-array\n```\n\n## Usage\n\n```js\nconst joinArray = require(\"join-non-empty-array\");\n\n// Join, but ignore the empty element\njoinArray([1, , 3, 4]);\n//=\u003e \"1,3,4\"\n\n// Built-in join method\n[1, , 3, 4].join();\n//=\u003e \"1,,3,4\"\n\n// Using flat ignores empty slots; but not slots with falsy values\n[0, , ' ', undefined, null, 2,3].flat().join();\n//=\u003e \"0, ,,,2,3\"\n\njoinArray([0, , ' ', undefined, null, 2,3]);\n//=\u003e \"0, ,undefined,null,2,3\"\n\nconst options = {ignoreFalsy: true, ignoreWhiteSpace: true};\njoinArray([0, , ' ', undefined, null, 2,3], options);\n//=\u003e \"0,2,3\"\n```\n\n## API\n\nJoin an array into a string with options.\n\n### Params\n\n* `array` {**Array**} (Required): Array to join together.\n* `joiner` {**String**} (Optional; default = `\",\"`): String used to join elements of the array.\n* `options` {**Object**} (Optional).\n\n### Options\n\n#### `ignoreWhiteSpace`\n\nRemove white space in array elements before determining if it is empty. The elements are *not* modified.\n\n_Type: `boolean`_\u003cbr /\u003e\n_default is set to `false`_\n\n```js\nconst array = [\n  \"\\t\", // empty when whitespace is ignored\n  \"1 \", // not modified\n  \"\\t2\" // not modified\n];\n\njoinArray(array);\n//=\u003e \"\\t,1 ,\\t2\"\n\njoinArray(array, \",\", {ignoreWhiteSpace: true});\n//=\u003e \"1 ,\\t2\"\n```\n\n#### `trimEntries`\n\nRemove white space from all elements in the array before joining.\n\n_Type: `boolean`_\u003cbr /\u003e\n_default is set to `false`_\n\n```js\nconst array = [\n  \"\\t\", // empty when whitespace is trimmed\n  \"1 \", // white space removed\n  \"\\t2\" // white space removed\n];\n\njoinArray(array);\n//=\u003e \"\\t,1 ,\\t2\"\n\njoinArray(array, \",\", {trimEntries: true});\n//=\u003e \"1,2\"\n```\n\n#### `ignoreFalsy`\n\nTreat falsy values (**except zero!**) as an empty element.\n\n_Type: `boolean`_\u003cbr /\u003e\n_default is set to `false`_\n\n```js\nconst array = [\n  1,\n  null,      // falsy\n  \"2\",\n  0,         // falsy, but NOT treated as such!\n  undefined, // falsy\n  false      // umm, yeah falsy\n];\n\njoinArray(array);\n//=\u003e \"1,null,2,0,undefined,false\"\n\njoinArray(array, \",\", {ignoreFalsy: true});\n//=\u003e \"1,2,0\" // zero is not treated as a falsy value!\n```\n\n#### `appendJoiner`\n\nAppend the joiner to the end of the joined array\n\n_Type: `boolean`_\u003cbr /\u003e\n_default is set to `false`_\n\n```js\nconst array = [\n  \"\",   // empty when whitespace is trimmed away\n  \"1 \", // not modified\n  \" 2\"  // not modified\n];\n\njoinArray(array);\n//=\u003e \"1 , 2\"\n\njoinArray(array, \",\", {appendJoiner: true});\n//=\u003e \"1 , 2,\"\n```\n\n#### `flattenDepth`\n\nThe library uses [`flat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) set to this depth - *Added in v1.1.0*.\n\n_Type: `number`_\u003cbr /\u003e\n_default is set to `Infinity`_\n\n**Note** `flat()` removes empty slots in the array to the set depth. Any\nnested array(s) of greater depth are automatically flattened when `join()` is\napplied.\n\nSet this option to zero (`0`) to skip using the flatten function\n\n```js\nconst array = [0, , 1, \" \", [\" 3\", null, [, 5, undefined, [, 7]]]];\n\narray.join();\n//=\u003e \"0,,1, , 3,,,5,,,7\"\n\narray.flat(Infinity).join();\n//=\u003e \"0,1, , 3,,5,,7\"\n\njoinArray(array, \"x\", {flattenDepth: 0});\n//=\u003e \"0x1x x 3,,,5,,,7\"\n\njoinArray(array, \"x\", {flattenDepth: 1});\n//=\u003e \"0x1x x 3xnullx,5,,,7\"\n\njoinArray(array, \"x\", {flattenDepth: 2});\n//=\u003e \"0x1x x 3xnullx5xundefinedx,7\"\n\njoinArray(array, \"x\", {flattenDepth: 3});\n//=\u003e \"0x1x x 3xnullx5xundefinedx7\"\n\njoinArray(array, \"x\"); // flattenDepth = Infinity by default\n//=\u003e \"0x1x x 3xnullx5xundefinedx7\"\n```\n\n## Examples\n\n```js\nconst joinArray = require(\"join-non-empty-array\");\n\n// params: array, joiner, options\nconsole.log(joinArray([0, 1, \" \" , 2, 3], \";\", {ignoreWhiteSpace: true}));\n//=\u003e \"0;1;2;3\"\n\nconst opts = {\n  ignoreWhiteSpace: true,\n  trimEntries: true,\n  ignoreFalsy: true,\n  appendJoiner: true,\n  flattenDepth: Infinity // default value\n};\nlet array = [\"\\na\", NaN, \"b\\n\", 0, \"   \", \"d\\t\", \"\\t\\n\", \"\\tf\\n \"];\nconsole.log(joinArray(array, \"-\", opts));\n//=\u003e \"a-b-0-d-f-\"\n\narray = [0, , 1, \" \", [\" 3\", null, [, 5, undefined, [, 7]]]];\nconsole.log(joinArray(array, \"x\", opts));\n//=\u003e \"0x1x3x5x7x\"\n```\n\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmottie%2Fjoin-non-empty-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmottie%2Fjoin-non-empty-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmottie%2Fjoin-non-empty-array/lists"}