@dxworks/node-utils

`npm i @dxworks/node-utils`

This utility library is no longer being maintained. Please use template repositories at https://github.com/dxworks or the plaited-cli npm package
Last updated a year ago by edwardirby .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @dxworks/node-utils 
SYNC missed versions from official npm registry.

@dxworks/node-utils

npm i @dxworks/node-utils

DX Works' NodeJS Utility functions and re-export of @dxworks/utils

  • arrayIsEmpty
  • callAll
  • camelCaseToDash
  • compose
  • css
  • dashToCamelCase
  • escape
  • unescape
  • get
  • hashString
  • html
  • pipe
  • removeWhiteSpace
  • _throw
  • trueTypeOf
  • ueid

Usage example: import { exportName } from '@dxworks/node-utils'

Modules

buildIndex()

A utility for building out index html pages at dest with a given page function

Example

await buildIndex({
  dest: /* <path to folder where file should be built> */,
  tpl: /* <string template of file> */,
})

buildPlaysets()

A utility that builds html files of your playground playsets and returns a route object that contains routes to

Example

await buildPlaysets({
    src: /* <path to playset dir> */,
    root: /* <path to root of public dir> */,
    ext: /* <path playset file extension eg playset.js> */,
    files: /* <glob of playset file paths> */,
  });

buildSvgIcon()

A utility for generating the boiler plate of an svg-icon component. It will generate the component in the same directory as the icons.

Example: use

await buildSvgIcon(/* Directory of svg icons*/);

Sample boilerplate

import {
  createShadow,
  html,
  css,
  attr,
  query,
} from '@dxworks/dom-utils';

const style = css`
:host {
  --fill: var(--fill, considerFallbackFill)
  display: inline-block;
}
.icon {
  display: none;
  fill: var(--fill);
}
:host([size='iconSize']){
  --icon-size: var(--iconSize);
}
:host([icon]) > .icon {
  display: inline-block;
  height: var(--icon-size);
  width: var(--icon-size);
  fill: var(--fill);
}
`;

const template = () => html`
<-- Your sprite will go here -->
<svg class="icon"><use xlink:href=""></use></svg>
`;


createShadow({
  tag: 'svg-icon',
  template,
  style,
  component: base => class extends base {
    static get observedAttributes() {
      return [
        'icon',
      ];
    }

    handleIcon(arg, value) {
      const { set } = attr(query('use', this.shadowRoot));
      return arg
        ? set('xlink:href', `#${value}`)
        : set('xlink:href', null);
    }

    attributeChangedCallback(name, oldValue, newValue) {
      const hasValue = newValue !== null;
      switch (name) {
        case 'icon': {
          this.handleIcon(hasValue, newValue);
          break;
        }
        default: {
          break;
        }
      }
    }
  },
});

copyFiles()

A simple utility for copying files from one place to another.

Example

await copyFiles({
  dest: /* path to files dir */,
  files: /* glob of file paths */,
})

reloadScript

String fragment to place in html files to enable auto-reloading when using servor.

Example

import { reloadScript, html } from '@dxworks/node-utils';
html`${reloadScript}`;

servor()

This is a fork of the servor project using hapi. It is a start static file server for rapid SPA/Hybrid-SPA development. It returns a server object to enable graceful stopping of server.

It provides a JS API, dynamic port assignment when needed, graceful stopping of the server, event sourcing, and chokidar for more accurate watching.

Example

const server = await servor({
  port: /* defaults to 5000 */
  browser: /* defaults to true will open browse tab */,
  reload: /* default to true will reload when files in roo change */,
  root: /* path to public dir */,
});

/* server can be stopped like so */
server.stop();

Current Tags

  • 0.2.0                                ...           latest (a year ago)

6 Versions

  • 0.2.0 [deprecated]           ...           a year ago
  • 0.1.4 [deprecated]           ...           a year ago
  • 0.1.3 [deprecated]           ...           a year ago
  • 0.1.2 [deprecated]           ...           a year ago
  • 0.1.1 [deprecated]           ...           a year ago
  • 0.1.0 [deprecated]           ...           a year ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 6
Dependencies (7)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2017 © taobao.org |