{"id":19074006,"url":"https://github.com/edtoken/array-to-grid","last_synced_at":"2025-04-28T19:20:32.485Z","repository":{"id":57184157,"uuid":"104805074","full_name":"edtoken/array-to-grid","owner":"edtoken","description":"Creating a Grid from an Array","archived":false,"fork":false,"pushed_at":"2018-01-12T16:10:52.000Z","size":12,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T04:41:02.309Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/array-to-grid","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/edtoken.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-09-25T21:42:47.000Z","updated_at":"2021-09-06T08:22:12.000Z","dependencies_parsed_at":"2022-08-23T01:31:00.800Z","dependency_job_id":null,"html_url":"https://github.com/edtoken/array-to-grid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edtoken%2Farray-to-grid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edtoken%2Farray-to-grid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edtoken%2Farray-to-grid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edtoken%2Farray-to-grid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edtoken","download_url":"https://codeload.github.com/edtoken/array-to-grid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251372539,"owners_count":21578967,"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-11-09T01:49:23.247Z","updated_at":"2025-04-28T19:20:32.469Z","avatar_url":"https://github.com/edtoken.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Array to Grid\nCreating a Grid from an Array of elements\n\n[![Build Status](https://api.travis-ci.org/edtoken/array-to-grid.svg?branch=master)](https://travis-ci.org/edtoken/array-to-grid)\n[![npm version](https://badge.fury.io/js/array-to-grid.svg)](https://badge.fury.io/js/array-to-grid)\n[![Maintainability](https://api.codeclimate.com/v1/badges/63008b6460da6fcf114b/maintainability)](https://codeclimate.com/github/edtoken/array-to-grid/maintainability)\n[![HitCount](http://hits.dwyl.com/edtoken/array-to-grid.svg)](http://hits.dwyl.com/edtoken/array-to-grid)  \n\n[![NPM](https://nodei.co/npm/array-to-grid.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/array-to-grid/)  \n[![NPM](https://nodei.co/npm-dl/array-to-grid.png?height=3)](https://nodei.co/npm/array-to-grid/)  \n\n\n\ninput\n``` \n[\n    {_size: 1, ...}, \n    {_size: 0.5, ...}, \n    {_size: 0.4, ...}, \n    {_size: 0.2, ...}\n]\n```\n\noutput\n``` \n[\n    [{_size: 1, _width: 12, ...}],\n    [{_size: 0.5, _width: 6, ...}, {_size: 0.4, _width: 6, ...}],\n    [{_size: 0.2, _width: 2, ...}]\n]\n```\n\n## Install\n```\nnpm install array-to-grid --save\n```\n\n## Usage\n\n### Properties\n* `  arrayToGrid.defaultColumnSize  ` default column *_size* value\n* `  arrayToGrid.defaultRowSize  ` sum of width for 1 row\n\n### Arguments\n```\n/**\n * @param {Array} elements - The array of elements for grid\n * @param {Integer} [rowSize=12] rowSize - Row size, default 12 (for example bootstrap grid size is 12)\n * @param {Integer} [columnSize=0.5] columnSize - Column size, default 0.5 ( 1/2 of row )\n * Returns a new array\n */\n \narrayToGrid(elements:Array, rowSize:Integer, columnSize:Integer) \n```\n\n### Make a Form\n```\n/**\n * Сreate a grid for the form\n * Use Bootstrap classNames\n */\n \nvar arrayToGrid = require('array-to-grid');\n\nvar elements = [\n    {_size: 1, name: 'fullname'},\n    {_size: 0.5, name: 'email'},\n    {_size: 0.5, name: 'password'}\n];\n\nvar rows = arrayToGrid(elements, 12);\n\nvar fields = rows.map((row, indx) =\u003e {\n    return (\u003cdiv className='row'\u003e\n        {row.elements.map((el, elIndx) =\u003e {\n            return (\u003cdiv className={'col-xs-' + el._width}\u003e\n                \u003cinput name={el.name}/\u003e\n            \u003c/div\u003e)\n        })}\n    \u003c/div\u003e)\n});\n\n```\n\n### Make a page blocks\n```\nimport React, {Component} from 'react';\nimport arrayToGrid from 'array-to-grid';\n\narrayToGrid.defaultColumnSize = 0.3;\narrayToGrid.defaultRowSize = 12;\n\nconst widgets = [\n    {_size: 1, data: {title: 'widget-1'}},\n    {data: {title: 'widget-2'}},\n    {_size: 0.1, data: {title: 'widget-3'}},\n    {_size: 0.9, data: {title: 'widget-4'}},\n    {data: {title: 'widget-5'}},\n    {_size: 0.5, data: {title: 'widget-6'}},\n    {_size: 0.3, data: {title: 'widget-7'}},\n    {_size: 0.3, data: {title: 'widget-8'}},\n    {_size: 0.7, data: {title: 'widget-9'}},\n    {_size: 0.9, data: {title: 'widget-10'}},\n    {_size: 0.1, data: {title: 'widget-11'}},\n];\n\nclass Widget extends Component {\n\n    render() {\n        return (\u003cspan className={this.props.className}\u003e\n    \u003ch2\u003eColumn\u003c/h2\u003e\n        \u003ch1\u003e{this.props.title}\u003c/h1\u003e\n        \u003ch2\u003e{this.props._size}\u003c/h2\u003e\n        \u003c/span\u003e);\n    }\n}\n\nclass Page extends Component {\n\n    render() {\n        let renderedWidgets = widgets.filter(w =\u003e (!w._size || w._size \u003e 0.5));\n        let widgetsGrid = arrayToGrid(renderedWidgets, 12);\n\n        return (\u003cdiv\u003e\n            {widgetsGrid.map((row, rowIndx) =\u003e {\n                return (\u003cdiv\n                    className='row'\n                    key={['row', rowIndx, row.length].join('.')}\u003e\n                    \n                    \u003ch1\u003eRow\u003c/h1\u003e\n                    \n                    {row.map((el, colIndx) =\u003e (\n                        \u003cWidget key={['col', rowIndx, colIndx].join('.')}\n                                className={'col-xs-' + el._size}\n                                title={el.title}\n                                _size={el._size}/\u003e)\n                    )}\n                \u003c/div\u003e)\n            })}\n        \u003c/div\u003e)\n    }\n}\n```\n\n## Unit testing\n```\nnpm test\n```\n\n## Changelog\n[CHANGELOG.md](./CHANGELOG.md)\n\n## License\n[MIT](https://github.com/edtoken/array-to-grid/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedtoken%2Farray-to-grid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedtoken%2Farray-to-grid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedtoken%2Farray-to-grid/lists"}