{"id":21082261,"url":"https://github.com/olsonpm/tedent","last_synced_at":"2025-03-14T04:43:09.015Z","repository":{"id":80606811,"uuid":"142501323","full_name":"olsonpm/tedent","owner":"olsonpm","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-23T16:43:27.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-01-20T23:45:41.335Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/olsonpm.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":"2018-07-26T22:44:51.000Z","updated_at":"2021-03-23T16:43:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"1229ae70-aacb-44c8-ad09-cb57af53518d","html_url":"https://github.com/olsonpm/tedent","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Ftedent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Ftedent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Ftedent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olsonpm%2Ftedent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olsonpm","download_url":"https://codeload.github.com/olsonpm/tedent/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243526853,"owners_count":20305112,"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-19T20:13:29.281Z","updated_at":"2025-03-14T04:43:08.991Z","avatar_url":"https://github.com/olsonpm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tedent\n\nKeep your multi-line templated strings lookin' good :sunglasses:\n\n\u003cbr\u003e\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n**Table of Contents**\n\n- [What is it?](#what-is-it)\n- [What does the name stand for?](#what-does-the-name-stand-for)\n- [Why create it?](#why-create-it)\n- [Simple Usage](#simple-usage)\n- [How the indentation works](#how-the-indentation-works)\n- [Important Usage Notes](#important-usage-notes)\n  - [edge-cases and input requirements](#edge-cases-and-input-requirements)\n- [Test](#test)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n\u003cbr\u003e\n\n### What is it?\n\n- A function similar to [dedent](https://github.com/dmnd/dedent) just with\n  different semantics\n\n\u003cbr\u003e\n\n### What does the name stand for?\n\n- `Te`mplate string\n- in`dent`ation\n\nnames are hard\n\n\u003cbr\u003e\n\n### Why create it?\n\n- dedent didn't handle the following case like I wanted\n\n```js\n//\n// any multi-line indented string will do, but stringifying an object is the\n//   common case for me\n//\nconst boroughs = ['Brooklyn', 'Manhattan'],\n  boroughsString = JSON.stringify(boroughs, null, 2)\n\nconsole.log(\n  dedent(`\n    New York boroughs\n    ${boroughs}\n  `)\n)\n\n/*\nexpected:\nNew York boroughs\n[\n  \"Brooklyn\",\n  \"Manhattan\"\n]\n\nactual:\nNew York boroughs\n  [\n\"Brooklyn\",\n\"Manhattan\"\n]\n*/\n```\n\n\u003cbr\u003e\n\n### Simple Usage\n\n```js\nimport tedent from 'tedent'\n\nconsole.log(\n  tedent(`\n    This will be indented\n      as you expect\n  `)\n)\n\n// writes:\n// This will be indented\n//   as you expect\n```\n\n\u003cbr\u003e\n\n### How the indentation works\n\nThe indentation logic is fairly convoluted in order to make the following work\n\n```js\nconst jstring = anObject =\u003e JSON.stringify(anObject, null, 2)\n\nconsole.log(\n  tedent(`\n    header\n\n      object 1: ${jstring(object1)}\n\n      object 2: ${jstring(object2)}\n  `)\n)\n\n//---------\n// outputs\n//---------\n// header\n//\n//   object 1: {\n//     ...properly indented object1 contents...\n//   }\n//\n//   object 2: {\n//     ...properly indented object2 contents...\n//   }\n//\n```\n\nBecause the indentation logic is both young and convoluted, please refer to\n[the code](index.js) and [tests](test.js) for details. The library is not that\nbig and if you have any questions please create a github issue.\n\n\u003cbr\u003e\n\n### Important Usage Notes\n\n- First of all, this library doesn't handle tabs. I will accept a PR\n  with support\n\n- Secondly, if you always use `tedent` like the following\n\n  ```js\n  tedent(`\n    at least one line\n  `)\n  ```\n\n  then you shouldn't run into any issues. However we all know input can be\n  tricky so `tedent` has a few edge-cases built-in as well as input requirements\n\n#### edge-cases and input requirements\n\n- if the first argument is anything but `undefined` or `typeof 'string'` then an error will be thrown\n- if you pass `undefined` an empty string is returned\n- if you pass a string with three or more lines, then\n  - the first and last lines must contain only whitespace\n  - the second line must contain a non-whitespace character\n  - _an error will be thrown if the above two conditions are not met_\n- if you pass a string with fewer than 3 lines\n  - if they only contain whitespace then an empty string is returned\n  - otherwise an error is thrown\n- finally, all trailing whitespace from the result is trimmed\n\nI didn't feel it necessary to explain the reasons for my choices in handling\nedge-cases, but if you have questions please ask via github issues.\n\n\u003cbr\u003e\n\n### Test\n\n`./run test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folsonpm%2Ftedent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folsonpm%2Ftedent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folsonpm%2Ftedent/lists"}