{"id":16173152,"url":"https://github.com/joeferner/node-sf","last_synced_at":"2025-03-19T00:30:46.558Z","repository":{"id":57357160,"uuid":"3457164","full_name":"joeferner/node-sf","owner":"joeferner","description":"String formatting library for node.js","archived":false,"fork":false,"pushed_at":"2018-12-31T01:02:00.000Z","size":43,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-28T13:18:42.477Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joeferner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-16T05:05:45.000Z","updated_at":"2022-01-20T11:23:41.000Z","dependencies_parsed_at":"2022-09-26T16:32:54.830Z","dependency_job_id":null,"html_url":"https://github.com/joeferner/node-sf","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeferner%2Fnode-sf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeferner%2Fnode-sf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeferner%2Fnode-sf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeferner%2Fnode-sf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joeferner","download_url":"https://codeload.github.com/joeferner/node-sf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243955757,"owners_count":20374373,"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-10-10T04:06:46.832Z","updated_at":"2025-03-19T00:30:46.297Z","avatar_url":"https://github.com/joeferner.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sf\n\n[![Build Status](https://secure.travis-ci.org/joeferner/node-sf.png)](http://travis-ci.org/joeferner/node-sf)\n\nString formatting library for node.js.\n\n## Installation\n\n```bash\n$ npm install sf\n```\n\n## Quick Examples\n\n```javascript\nvar sf = require(\"sf\");\n\nsf(\"{who} has a {what}\", { who: 'dog', what: 'tail' });\n// returns: dog has a tail\n\nsf(\"{0} has a {1}\", 'dog', 'tail');\n// returns: dog has a tail\n\nsf(\"{0:#,##0.00}\", 2123.1);\n// returns: 2,123.10\n\nsf(\"{0,15:#,##0.00}\", 2123.1);\n// returns:        2,123.10\n\nsf(\"{a.b}\", { a: { b: 'test' }});\n// returns: test\n\nsf(\"{a.z.c}\", { a: { b: 'test' }});\n// throws an error\n\nsf(\"{a.?z.?c}\", { a: { b: 'test' }});\n// returns:\n\nsf(\"{a[0]}\", { a: [ 'foo', 'bar' ]});\n// returns: foo\n\nsf(\"{a[-1]}\", { a: [ 'foo', 'bar' ]});\n// returns: bar\n\nsf.log(\"{who} has a {what}\", { who: 'dog', what: 'tail' });\n// outputs to standard out: dog has a tail\n\nsf(\"{0:^d 'Days,' h:mm:ss.fff}\", new sf.TimeSpan(8173818181));\n// returns: 94 Days, 14:30:18.181\n```\n\n## Format Specifiers\n\nThe format is similar to C#'s string.format. The text inside the curly braces is {indexOrName[,alignment][:formatString]}.\nIf alignment is positive the text is right aligned. If alignment is negative it will be left aligned.\n\n### Object\n\n| Specifier | Name                         |\n|-----------|------------------------------|\n| json      | JSON.stringify               |\n| inspect   | util.inspect                 |\n\n### Numbers\n\n| Specifier | Name                         | Example          | Output         |\n|-----------|------------------------------|------------------|----------------|\n| 0         | Zero placeholder             | {0:00.0000}      | 02.1200        |\n| #         | Digit placeholder            | {0:#,###}        | 1,234          |\n| x         | Lowercase hex                | {0:x4}           | 01fc           |\n| X         | Uppercase hex                | {0:X4}           | 01FC           |\n\n### Dates\n\n| Specifier | Name                            | Example                         |\n|-----------|---------------------------------|---------------------------------|\n| sd        | Short date                      | 10/12/2002                      |\n| D         | Long date                       | December 10, 2002               |\n| t         | Short time                      | 10:11 PM                        |\n| T         | Long time                       | 10:11:29 PM                     |\n| fdt       | Full date \u0026 time                | December 10, 2002 10:11 PM      |\n| F         | Full date \u0026 time (long)         | December 10, 2002 10:11:29 PM   |\n| g         | Default date \u0026 time             | 10/12/2002 10:11 PM             |\n| G         | Default date \u0026 time (long)      | 10/12/2002 10:11:29 PM          |\n| md        | Month day pattern               | December 10                     |\n| r         | RFC1123 date string             | Tue, 10 Dec 2002 22:11:29 +0500 |\n| s         | Sortable date string            | 2002-12-10T22:11:29             |\n| d         | Date single digit               | 1                               |\n| dd        | Date leading zero               | 01                              |\n| ddd       | Short day name                  | Mon                             |\n| dddd      | Long day name                   | Monday                          |\n| f         | Fraction of second (1 digit)    | 1                               |\n| ff        | Fraction of second (2 digit)    | 24                              |\n| fff       | Fraction of second (3 digit)    | 345                             |\n| h         | Hour 12-hour format 1 digit     | 5                               |\n| hh        | Hour 12-hour format 2 digits    | 05                              |\n| H         | Hour 24-hour format 1 digit     | 5                               |\n| HH        | Hour 24-hour format 2 digits    | 05                              |\n| mm        | Minutes 2 digits                | 23                              |\n| M         | Month single digit              | 2                               |\n| MM        | Month leading zero              | 02                              |\n| MMM       | Month short name                | Feb                             |\n| MMMM      | Month long name                 | February                        |\n| ss        | Seconds 2 digits                | 54                              |\n| tt        | AM/PM                           | AM                              |\n| yy        | Year 2 digits                   | 12                              |\n| yyyy      | Year 4 digits                   | 2012                            |\n| zz        | Time zone offset                | 05                              |\n| +zz       | Time zone offset leading +      | +05                             |\n| zzz       | Time zone offset full           | 05:00                           |\n| zzzz      | Time zone offset full           | 0500                            |\n| +zzzz     | Time zone offset full leading + | +0500                           |\n\n### sf.TimeSpan\n\n| Specifier | Name                | Example                |\n|-----------|---------------------|------------------------|\n| y         | Years               | 2                      |\n| M         | Months              | 6                      |\n| d         | Days                | 8                      |\n| h         | Hours               | 10                     |\n| m         | Minutes             | 15                     |\n| s         | Seconds             | 5                      |\n| f         | Fraction of Seconds | 9                      |\n\nIf you prefix the specifier with '^' you will get the total number of that value. For\nexample '^s' will output the total number of seconds in the time span. Where as 's' will\nonly output the number of seconds in a minute.\n\nIf you repeat characters the value will be prefixed with zeros.\n\n## sf.indent(str, options)\n\nHelper function to word wrap and indent a string.\n\n__Arguments__\n\n * str - The string to indent and wrap.\n * options\n  * prefix - The prefix to appear at the beginning of each new line.\n  * wordwrap - The maximum length of each line.\n\n## Helper Functions\n\n * sf.log(formatString [, args...]);\n * sf.info(formatString [, args...]);\n * sf.warn(formatString [, args...]);\n * sf.error(formatString [, args...]);\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeferner%2Fnode-sf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoeferner%2Fnode-sf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeferner%2Fnode-sf/lists"}