Narcissistic Project Managers

    @heduapp/book-objects
    TypeScript icon, indicating that this package has built-in type declarations

    0.23.0 • Public • Published

    Book Objects

    Gist

    Business objects, basically, copy the structure of XML.
    Specific elements will have its own implementation which calculates values from data.
    Hence, there should be zero redundancy of the data.
    There are codecs for different purposes (parsing XML, saving business objects to DB or rendering using JSX).
    If there is an error in a source (i.e. typo in the XML) it should be fixed by the codec.

    Usage

    Install

    npm install git+ssh://ssh-config-name:HeduApp/book-objects.git#dist
    

    Decode book XML into business objects

    import * as BO from 'book-objects/business-object';
    import XMLCodec from 'book-objects/codec/xml-codec';
    const xmlCodec = new Codec.XMLCodec();
    const book = (await xmlCodec.decode(bookXML)) as BO.Book;

    Encode business objects into XML

    import XMLCodec from 'book-objects/codec/xml-codec';
    const xmlCodec = new XMLCodec();
    const bookXML = await xmlCodec.encode(book);

    Override component when encoding to JSX

    import JSXCodec from 'book-objects/codec/jsx-codec';
    import { BusinessObjectType } from 'book-objects/business-object';
    import { ComponentOverrides } from 'book-objects/jsx';
    import { CustomBook } from './CustomBook';
    import { CDNImage } from './CDNImage';
    const overrides: ComponentOverrides = {
        [BusinessObjectType.Book]: (book) => <CustomBook {...{book}} />,
        img: ({attributes: {src}}) => {
            const imageID = src as string;
            return (
                <CDNImage {...{imageID}} />
            );
        },
    };
    const jsxCodec = new JSXCodec(overrides);
    const EncodedComponent = await jsxCodec.encode(bookObject);

    Synchronous JSX encoding

    import JSXCodec from 'book-objects/codec/jsx-codec';
    const jsxCodec = new JSXCodec(overrides);
    const EncodedComponent = jsxCodec.encodeSync(bookObject);

    Contributing

    Tests

    Alsatian is used as a testing framework and test runner, Enzyme is used to test JSX.
    To run tests:

    npm run test
    npm run test-watch
    

    Code style

    Code style is enforced by prettier
    To prettify code:

    npm run prettier
    npm run prettier-watch
    

    Before pushing to master

    • [ ] Are all tests passing?
    • [ ] Have you ran prettier?

    Release new version

    npm version major|minor|patch # Should be same as the version in the commit message
    npm run release
    

    Keywords

    none

    Install

    npm i @heduapp/book-objects

    DownloadsWeekly Downloads

    1

    Version

    0.23.0

    License

    none

    Unpacked Size

    613 kB

    Total Files

    59

    Last publish

    Collaborators

    • hejny
    • pohy
    • heduapp