@onsvisual/svelte-components 0.1.47 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,11 +2,23 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/@onsvisual%2Fsvelte-components.svg)](https://www.npmjs.com/package/@onsvisual/svelte-components)
4
4
 
5
- A library of ONS Svelte components for projects large and small. Its codebase and docs borrow **heavily** from Reuters' fantastic [graphics-components](https://github.com/reuters-graphics/graphics-components) library.
6
-
7
- To update
8
- 1. Increment version in package.json
9
- 2. npm run build
10
- 3. Commit + push changes to github.
11
- 4. npm run deploy
12
- 5. npm publish
5
+ A library of ONS Svelte components for projects large and small. You can find documentation and examples of how to use these components on the [Storybook pages](https://onsvisual.github.io/svelte-components).
6
+
7
+ This component library is inspired by Reuters' fantastic [graphics-components](https://github.com/reuters-graphics/graphics-components) library. The components are adapted from the [ONS Design System](https://service-manual.ons.gov.uk/design-system/).
8
+
9
+ **To update the components:**
10
+
11
+ 1. Make changes to components
12
+ 2. Commit changes locally (describe your changes in the commit message)
13
+ 3. Increment version number in package.json
14
+ 4. ```npm run build``` (build the package + docs)
15
+ 5. Commit + push changes to GitHub (use version number eg. "v1.0.0" as commit message)
16
+ 6. ```npm run deploy``` (publish docs to GitHub Pages)
17
+ 7. ```npm publish``` (publish new version to NPM)
18
+
19
+ **To update the docs only:**
20
+
21
+ 1. Update story files (.stories.svelte .stories.mdx etc)
22
+ 2. Commit + push changes to GitHub
23
+ 3. ```npm run build:docs``` (build the docs)
24
+ 4. ```npm run deploy``` (publish docs to GitHub Pages)
@@ -1,4 +1,5 @@
1
1
  export function slugify(str: any, suffix?: boolean): string;
2
+ export function isNumeric(val: any): boolean;
2
3
  export function validDate(str: any): boolean;
3
4
  export function formatDate(str: any, locale?: string, opts?: {
4
5
  year: string;
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { format, ascending, descending } from "../../js/utils.js";
2
+ import { format, isNumeric, ascending, descending } from "../../js/utils.js";
3
3
 
4
4
  /**
5
5
  * An optional title for the table
@@ -126,7 +126,7 @@
126
126
  class="ons-table__cell"
127
127
  class:ons-table__cell--numeric="{col.numeric}"
128
128
  data-th="{col.label}"
129
- >{@html row[col.key] && col.numeric
129
+ >{@html col.numeric && isNumeric(row[col.key])
130
130
  ? format(row[col.key], col.dp)
131
131
  : row[col.key]
132
132
  ? row[col.key]
package/dist/js/utils.js CHANGED
@@ -16,6 +16,8 @@ export const slugify = (str, suffix = false) =>
16
16
  .concat(suffix ? `-${randomString()}` : "")
17
17
  : randomString();
18
18
 
19
+ export const isNumeric = (val) => isFinite(val) && val !== null;
20
+
19
21
  export const validDate = (str) => {
20
22
  if (!str) return false;
21
23
  const date = new Date(str);
@@ -34,7 +36,7 @@ export const formatDate = (
34
36
  };
35
37
 
36
38
  export const format = (val, dp = null) => {
37
- return dp
39
+ return Number.isInteger(dp)
38
40
  ? val.toLocaleString("en-GB", {
39
41
  minimumFractionDigits: dp,
40
42
  maximumFractionDigits: dp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",