Giter VIP home page Giter VIP logo

ssf's Introduction

ssf (SpreadSheet Format) is a pure-JS library to format data using ECMA-376 spreadsheet format codes (used in popular spreadsheet software packages).

Looker Note: Publishing to Nexus

Information about publishing updates to nexus available here

Installation

With npm:

$ npm install ssf

In the browser:

<script src="ssf.js"></script>

The browser exposes a variable SSF

When installed globally, npm installs a script ssf that renders the format string with the given arguments. Running the script with -h displays help.

The script will manipulate module.exports if available (e.g. in a CommonJS require context). This is not always desirable. To prevent the behavior, define DO_NOT_EXPORT_SSF.

Usage

SSF.format(fmt, val, opts) formats val using the format fmt.

If fmt is a string, it will be parsed and evaluated. If fmt is a number, the actual format will be the corresponding entry in the internal format table. For a raw numeric format like 000, the value should be passed as a string.

Date arguments are interpreted in the local time of the JS client.

The options argument may contain the following keys:

Option Name Default Description
date1904 false Use 1904 date system if true, 1900 system if false

Manipulating the Internal Format Table

Binary spreadsheet formats store cell formats in a table and reference by index. This library uses a global table:

SSF._table is the underlying object, mapping numeric keys to format strings.

SSF.load(fmt:string, idx:?number):number assigns the format to the specified index and returns the index. If the index is not specified, SSF will search the space for an available format slot pick an unused slot. For compatibility with the XLS and XLSB file formats, custom indices should be in the valid ranges 5-8, 23-26, 41-44, 63-66, 164-382 (see [MS-XLSB] 2.4.655 BrtFmt)

SSF.get_table() gets the internal format table (number to format mapping).

SSF.load_table(table) sets the internal format table.

Other Utilities

SSF.parse_date_code(val:number, opts:?any) parses val, returning an object:

type SSFDate = {
  D:number; /* number of whole days since relevant epoch, 0 <= D */
  y:number; /* integral year portion, epoch_year <= y */
  m:number; /* integral month portion, 1 <= m <= 12 */
  d:number; /* integral day portion, subject to gregorian YMD constraints */
  q:number; /* integral day of week (0=Sunday .. 6=Saturday) 0 <= q <= 6 */

  T:number; /* number of seconds since midnight, 0 <= T < 86400 */
  H:number; /* integral number of hours since midnight, 0 <= H < 24 */
  M:number; /* integral number of minutes since the last hour, 0 <= M < 60 */
  S:number; /* integral number of seconds since the last minute, 0 <= S < 60 */
  u:number; /* sub-second part of time, 0 <= u < 1 */
}

SSF.is_date(fmt:string):boolean returns true if fmt encodes a date format.

License

Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 license are reserved by the Original Author.

References

  • [ECMA-376] Office Open XML File Formats
  • [MS-XLSB] Excel (.xlsb) Binary File Format

Badges

Sauce Test Status

Build Status

Coverage Status

NPM Downloads

Dependencies Status

ghit.me

Analytics

ssf's People

Contributors

sheetjsdev avatar segfaultx64 avatar n8agrin avatar dutchgoose avatar wilg avatar aryeh-looker avatar richardczechowski avatar ssirowy avatar vvaldersteins avatar

Stargazers

 avatar Jon Repp avatar

Watchers

Ray Chen avatar Brian Madden avatar Rodney Gomes avatar Ben Porterfield avatar Krishna avatar ian waters avatar Jared avatar  avatar popmonkey avatar Chris Michel avatar Armando Padilla avatar Jeremy Britton avatar James Cloos avatar lloyd tabb avatar Bruce Bundy avatar Catherine Aurelio avatar Melissa Boucher avatar Richard Tai avatar Cecil Worsley avatar Micah Catlin avatar Danny Thorpe avatar Bryn Ryans avatar Michelle Wegenstein avatar Delaney Parker avatar My-Kell Davis avatar Ashley Cunningham avatar Natalie Uduwela avatar Phil Sharfstein avatar  avatar John Kaster avatar Spencer Butterfield avatar  avatar Alisa Tatarinova avatar Wyatt McGuire avatar Adam Markowitz avatar Andrew Wynn avatar Lindsey Meyer avatar Amrita Venkatraman avatar Andy Brown avatar Abby West avatar Alan McKenna avatar Maanul Shrivastava avatar  avatar Nick Caldwell avatar Macallan Brown avatar  avatar Tyler Dammann avatar Andrew Miner avatar David Leftwich avatar Jake Mitchell avatar Micah Bales avatar Andrew Zimmerman avatar  avatar Roland Blanton avatar Jack Scott avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.