diff --git a/docs/functions/addMahalanobisDistance.html b/docs/functions/addMahalanobisDistance.html index 680a1718..012233ee 100644 --- a/docs/functions/addMahalanobisDistance.html +++ b/docs/functions/addMahalanobisDistance.html @@ -1,6 +1,6 @@ -addMahalanobisDistance | Journalism - v1.15.0

Function addMahalanobisDistance

  • Computes the Mahalanobis distance from an origin object for each object in an array. The keys in the origin object are the dimensions considered (tested up to four dimensions but should work for more in theory). The function adds the key mahaDist in each object in the original array.

    +addMahalanobisDistance | Journalism - v1.15.1

    Function addMahalanobisDistance

    • Computes the Mahalanobis distance from an origin object for each object in an array. The keys in the origin object are the dimensions considered (tested up to four dimensions but should work for more in theory). The function adds the key mahaDist in each object in the original array.

      If you pass the option { similarity: true }, it will add another key similarity which goes from 1 to 0. The closer similarity is to 1, the closer the item is to the origin.

      Parameters

      • origin: Record<string, number>
      • data: Record<string, unknown>[]
      • options: {
            similarity?: boolean;
        } = {}
        • Optionalsimilarity?: boolean

      Returns Record<string, unknown>[]

      // Wines
      const data = [
      {'fixed acidity': 6.5, 'alcohol' : 11, ... },
      {'fixed acidity': 7.1, 'alcohol' : 12.2, ... },
      {'fixed acidity': 6.3, 'alcohol' : 10.5, ... }
      ]

      // We want the distance from this wine. All the keys in the origin will be used as variables. They need to be present in the data, of course.
      const origin = {'fixed acidity': 7.2, 'alcohol' : 11.3 }

      addMahalanobisDistance(origin, data)

      // We now have mahaDist in the data.
      data.sort((a, b) => a.mahaDist - b.mahaDist)

      // And data looks like this.
      //[
      // { 'fixed acidity': 7.2, alcohol: 11.3, mahaDist: 0 },
      // { 'fixed acidity': 7.5, alcohol: 10.5, mahaDist: 0.939 },
      // { 'fixed acidity': 7.3, alcohol: 11.4, mahaDist: 1.263 },
      // { 'fixed acidity': 6.5, alcohol: 13, mahaDist: 2.079 },
      // { 'fixed acidity': 7.1, alcohol: 12.2, mahaDist: 2.411 }
      //]

      // You can also pass the option similarity if you want.
      addMahalanobisDistance(origin, data, { similarity: true })

      // The data will have a similarity key going from 0 to 1.
      // [
      // { "fixed acidity": 7.2, alcohol: 11.3, mahaDist: 0, similarity: 1 },
      // { "fixed acidity": 7.5, alcohol: 10.5, mahaDist: 0.939, similarity: 0.611 },
      // { "fixed acidity": 7.3, alcohol: 11.4, mahaDist: 1.263, similarity: 0.476 },
      // { "fixed acidity": 6.5, alcohol: 13, mahaDist: 2.079, similarity: 0.138 },
      // { "fixed acidity": 7.1, alcohol: 12.2, mahaDist: 2.412, similarity: 0 }
      // ]
      -
    +
diff --git a/docs/functions/addZscore.html b/docs/functions/addZscore.html index 8ef9912a..b2daf71a 100644 --- a/docs/functions/addZscore.html +++ b/docs/functions/addZscore.html @@ -1,5 +1,5 @@ -addZscore | Journalism - v1.15.0

Function addZscore

  • Computes the Z-Score for a given variable in an array of objects. The function adds a new key with the format zScoreVariable in each object.

    -

    Parameters

    • data: Record<string, unknown>[]
    • variable: string

    Returns Record<string, unknown>[]

    // Let's say we have a data set like this.
    const data = [
    { grade: 1 },
    { grade: 4 },
    { grade: 7 },
    { grade: 2 },
    { grade: 6 },
    ]

    // We compute the Z-Score for the variable grade.
    addZScore(data, "grade")

    // We now have the key zScoreGrade in the data.
    // [
    // { grade: 1, zScoreGrade: -1.3155870289605438 },
    // { grade: 4, zScoreGrade: 0 },
    // { grade: 7, zScoreGrade: 1.3155870289605438 },
    // { grade: 2, zScoreGrade: -0.8770580193070292 },
    // { grade: 6, zScoreGrade: 0.8770580193070292 },
    // ] +addZscore | Journalism - v1.15.1

    Function addZscore

    • Computes the Z-Score for a given variable in an array of objects. By default, the function adds a new key zScore in each object, but you can change it by passing this option as the last parameter { newKey: "myNewKey" }.

      +

      Parameters

      • data: Record<string, unknown>[]
      • variable: string
      • options: {
            newKey?: string;
        } = {}
        • OptionalnewKey?: string

      Returns Record<string, unknown>[]

      // Let's say we have a data set like this.
      const data = [
      { grade: 1 },
      { grade: 4 },
      { grade: 7 },
      { grade: 2 },
      { grade: 6 },
      ]

      // We compute the Z-Score for the variable grade.
      addZScore(data, "grade")

      // We now have the key zScore in the data.
      // [
      // { grade: 1, zScore: -1.3155870289605438 },
      // { grade: 4, zScore: 0 },
      // { grade: 7, zScore: 1.3155870289605438 },
      // { grade: 2, zScore: -0.8770580193070292 },
      // { grade: 6, zScore: 0.8770580193070292 },
      // ]

      // If you want a specific new key, use the options.
      addZScore(data, "grade", { newKey: "zScoreGrade"})

      // We now have the key zScoreGrade in the data.
      // [
      // { grade: 1, zScoreGrade: -1.3155870289605438 },
      // { grade: 4, zScoreGrade: 0 },
      // { grade: 7, zScoreGrade: 1.3155870289605438 },
      // { grade: 2, zScoreGrade: -0.8770580193070292 },
      // { grade: 6, zScoreGrade: 0.8770580193070292 },
      // ]
      -
    +
diff --git a/docs/functions/adjustToInflation.html b/docs/functions/adjustToInflation.html index 199c23f1..775f4296 100644 --- a/docs/functions/adjustToInflation.html +++ b/docs/functions/adjustToInflation.html @@ -1,5 +1,5 @@ -adjustToInflation | Journalism - v1.15.0

Function adjustToInflation

  • Compute the adjusted to inflation amount of money, based on the Consumer Price Index. The options (last parameter) are optional.

    +adjustToInflation | Journalism - v1.15.1

    Function adjustToInflation

    • Compute the adjusted to inflation amount of money, based on the Consumer Price Index. The options (last parameter) are optional.

      // $100 in 1914 (CPI of 6.0) to 2023 value (CPI of 156.4)
      const adjustedAmount = adjustToInflation(100, 6.0, 156.4, { decimals: 0 })
      // returns 2607 dollars
      -

      Parameters

      • amount: number
      • amountCPI: number
      • targetCPI: number
      • options: {
            decimals?: number;
        } = {}
        • Optionaldecimals?: number

      Returns number

    +

    Parameters

    • amount: number
    • amountCPI: number
    • targetCPI: number
    • options: {
          decimals?: number;
      } = {}
      • Optionaldecimals?: number

    Returns number

diff --git a/docs/functions/arraysToData.html b/docs/functions/arraysToData.html index bb0fc672..7a082cd7 100644 --- a/docs/functions/arraysToData.html +++ b/docs/functions/arraysToData.html @@ -1,4 +1,4 @@ -arraysToData | Journalism - v1.15.0

Function arraysToData

  • Returns an array of objects from an object made of arrays.

    +arraysToData | Journalism - v1.15.1

    Function arraysToData

    • Returns an array of objects from an object made of arrays.

      For example, this data...

      {
      keyA: ["a", "b", "c"],
      keyB: [1, 2, 3],
      }
      @@ -7,4 +7,4 @@
      [
      { keyA: "a", keyB: 1 },
      { keyA: "b", keyB: 2 },
      { keyA: "c", keyB: 3 },
      ]
      -

      Parameters

      • data: {
            [key: string]: unknown[];
        }
        • [key: string]: unknown[]

      Returns {
          [key: string]: unknown;
      }[]

    +

    Parameters

    • data: {
          [key: string]: unknown[];
      }
      • [key: string]: unknown[]

    Returns {
        [key: string]: unknown;
    }[]

diff --git a/docs/functions/camelCase.html b/docs/functions/camelCase.html index 9b054384..45487597 100644 --- a/docs/functions/camelCase.html +++ b/docs/functions/camelCase.html @@ -1,5 +1,5 @@ -camelCase | Journalism - v1.15.0

Function camelCase

  • Formats a string to camel case.

    +camelCase | Journalism - v1.15.1

    Function camelCase

    • Formats a string to camel case.

      // Returns journalismIsAwesome
      const text = camelCase("Journalism is awesome")
      -

      Parameters

      • input: string

      Returns string

    +

    Parameters

    • input: string

    Returns string

diff --git a/docs/functions/capitalize.html b/docs/functions/capitalize.html index 38a2505b..7e98a60e 100644 --- a/docs/functions/capitalize.html +++ b/docs/functions/capitalize.html @@ -1,5 +1,5 @@ -capitalize | Journalism - v1.15.0

Function capitalize

  • Capitalizes the first character of a string.

    +capitalize | Journalism - v1.15.1

    Function capitalize

    • Capitalizes the first character of a string.

      // Returns 'Journalism'.
      const text = capitalize('journalism')
      -

      Parameters

      • string: string

      Returns string

    +

    Parameters

    • string: string

    Returns string

diff --git a/docs/functions/createDirectory.html b/docs/functions/createDirectory.html index 035bfca2..ffac2b7d 100644 --- a/docs/functions/createDirectory.html +++ b/docs/functions/createDirectory.html @@ -1,5 +1,5 @@ -createDirectory | Journalism - v1.15.0

Function createDirectory

  • Creates folders recursively if they don't exist.

    +createDirectory | Journalism - v1.15.1

    Function createDirectory

    • Creates folders recursively if they don't exist.

      // Creates folders if they don't exist
      createDirectory("./data/json")

      // This will give the same result. A file with an extension at the end of the path will be ignored.
      createDirectory("./data/json/items.json")
      -

      Parameters

      • path: string

      Returns void

    +

    Parameters

    • path: string

    Returns void

diff --git a/docs/functions/dataAsCsv.html b/docs/functions/dataAsCsv.html index e53e2747..e34f6a77 100644 --- a/docs/functions/dataAsCsv.html +++ b/docs/functions/dataAsCsv.html @@ -1,5 +1,5 @@ -dataAsCsv | Journalism - v1.15.0

Function dataAsCsv

  • Convert an array of objects into CSV format.

    +dataAsCsv | Journalism - v1.15.1

    Function dataAsCsv

    • Convert an array of objects into CSV format.

      const data = [
      { firstName: "Graeme", lastName: "Bruce" },
      { firstName: "Nael", lastName: "Shiab" },
      ]

      const csv = dataAsCsv(data)
      // Returns "firstName,lastName\nGraeme,Bruce\nNael,Shiab"
      -

      Parameters

      • arrayOfObjects: {
            [key: string]: unknown;
        }[]

      Returns string

    +

    Parameters

    • arrayOfObjects: {
          [key: string]: unknown;
      }[]

    Returns string

diff --git a/docs/functions/dataToArrays.html b/docs/functions/dataToArrays.html index d4dd6920..5e5683e7 100644 --- a/docs/functions/dataToArrays.html +++ b/docs/functions/dataToArrays.html @@ -1,4 +1,4 @@ -dataToArrays | Journalism - v1.15.0

Function dataToArrays

  • Returns an object made of arrays from an array of objects.

    +dataToArrays | Journalism - v1.15.1

    Function dataToArrays

    • Returns an object made of arrays from an array of objects.

      For example, this data...

      [
      { keyA: "a", keyB: 1 },
      { keyA: "b", keyB: 2 },
      { keyA: "c", keyB: 3 },
      ]
      @@ -7,4 +7,4 @@
      {
      keyA: ["a", "b", "c"],
      keyB: [1, 2, 3],
      }
      -

      Parameters

      • data: {
            [key: string]: unknown;
        }[]

      Returns {
          [key: string]: unknown[];
      }

      • [key: string]: unknown[]
    +

    Parameters

    • data: {
          [key: string]: unknown;
      }[]

    Returns {
        [key: string]: unknown[];
    }

    • [key: string]: unknown[]
diff --git a/docs/functions/distance.html b/docs/functions/distance.html index fa8eff65..3e16be26 100644 --- a/docs/functions/distance.html +++ b/docs/functions/distance.html @@ -1,5 +1,5 @@ -distance | Journalism - v1.15.0

Function distance

  • Compute the distance in kilometres based on longitude and latitude. The options (last parameter) are optional.

    +distance | Journalism - v1.15.1

    Function distance

    • Compute the distance in kilometres based on longitude and latitude. The options (last parameter) are optional.

      const distance = distance(-73.66, 45.51, -79.43, 43.66, { decimals: 0 })
      // returns 501
      -

      Parameters

      • lon1: number
      • lat1: number
      • lon2: number
      • lat2: number
      • options: {
            decimals?: number;
        } = {}
        • Optionaldecimals?: number

      Returns number

    +

    Parameters

    • lon1: number
    • lat1: number
    • lon2: number
    • lat2: number
    • options: {
          decimals?: number;
      } = {}
      • Optionaldecimals?: number

    Returns number

diff --git a/docs/functions/downloadFile.html b/docs/functions/downloadFile.html index d3f8c2cc..19dc584f 100644 --- a/docs/functions/downloadFile.html +++ b/docs/functions/downloadFile.html @@ -1,5 +1,5 @@ -downloadFile | Journalism - v1.15.0

Function downloadFile

  • Downloads a file.

    +downloadFile | Journalism - v1.15.1

    Function downloadFile

    • Downloads a file.

      await dowloadFile("http://some-website.com/data.csv", "./downloads/data.csv" )
       
      -

      Parameters

      • url: string
      • filePath: string

      Returns Promise<void>

    +

    Parameters

    • url: string
    • filePath: string

    Returns Promise<void>

diff --git a/docs/functions/formatDate.html b/docs/functions/formatDate.html index 66feac9f..d67b9c09 100644 --- a/docs/functions/formatDate.html +++ b/docs/functions/formatDate.html @@ -1,6 +1,6 @@ -formatDate | Journalism - v1.15.0

Function formatDate

  • Format a Date as a string with a specific format and a specific style. To format as UTC Date, set the utc option to true.

    +formatDate | Journalism - v1.15.1

    Function formatDate

    • Format a Date as a string with a specific format and a specific style. To format as UTC Date, set the utc option to true.

      const date = new Date("2023-01-01T01:35:00.000Z")
      const string = formatDate(date, "Month DD, YYYY, at HH:MM period", { utc: true, abbreviations: true })
      // returns "Jan. 1, 2023, at 1:35 p.m."

      Options can be passed as the last parameter. Pass {style: "rc"} to parse dates in French.

      -

      Parameters

      • date: Date
      • format:
            | "YYYY-MM-DD"
            | "YYYY-MM-DD HH:MM:SS TZ"
            | "DayOfWeek, Month Day"
            | "Month DD"
            | "Month DD, HH:MM period"
            | "Month DD, HH:MM period TZ"
            | "DayOfWeek, HH:MM period"
            | "DayOfWeek, HH:MM period TZ"
            | "Month DD, YYYY"
            | "Month DD, YYYY, at HH:MM period"
            | "Month DD, YYYY, at HH:MM period TZ"
            | "DayOfWeek"
            | "Month"
            | "YYYY"
            | "MM"
            | "DD"
            | "HH:MM period"
            | "HH:MM period TZ"
      • options: {
            abbreviations?: boolean;
            noZeroPadding?: boolean;
            style?: "cbc" | "rc";
            timeZone?:
                | "Canada/Atlantic"
                | "Canada/Central"
                | "Canada/Eastern"
                | "Canada/Mountain"
                | "Canada/Newfoundland"
                | "Canada/Pacific"
                | "Canada/Saskatchewan"
                | "Canada/Yukon";
            utc?: boolean;
        } = {}
        • Optionalabbreviations?: boolean
        • OptionalnoZeroPadding?: boolean
        • Optionalstyle?: "cbc" | "rc"
        • OptionaltimeZone?:
              | "Canada/Atlantic"
              | "Canada/Central"
              | "Canada/Eastern"
              | "Canada/Mountain"
              | "Canada/Newfoundland"
              | "Canada/Pacific"
              | "Canada/Saskatchewan"
              | "Canada/Yukon"
        • Optionalutc?: boolean

      Returns string

    +

    Parameters

    • date: Date
    • format:
          | "YYYY-MM-DD"
          | "YYYY-MM-DD HH:MM:SS TZ"
          | "DayOfWeek, Month Day"
          | "Month DD"
          | "Month DD, HH:MM period"
          | "Month DD, HH:MM period TZ"
          | "DayOfWeek, HH:MM period"
          | "DayOfWeek, HH:MM period TZ"
          | "Month DD, YYYY"
          | "Month DD, YYYY, at HH:MM period"
          | "Month DD, YYYY, at HH:MM period TZ"
          | "DayOfWeek"
          | "Month"
          | "YYYY"
          | "MM"
          | "DD"
          | "HH:MM period"
          | "HH:MM period TZ"
    • options: {
          abbreviations?: boolean;
          noZeroPadding?: boolean;
          style?: "cbc" | "rc";
          timeZone?:
              | "Canada/Atlantic"
              | "Canada/Central"
              | "Canada/Eastern"
              | "Canada/Mountain"
              | "Canada/Newfoundland"
              | "Canada/Pacific"
              | "Canada/Saskatchewan"
              | "Canada/Yukon";
          utc?: boolean;
      } = {}
      • Optionalabbreviations?: boolean
      • OptionalnoZeroPadding?: boolean
      • Optionalstyle?: "cbc" | "rc"
      • OptionaltimeZone?:
            | "Canada/Atlantic"
            | "Canada/Central"
            | "Canada/Eastern"
            | "Canada/Mountain"
            | "Canada/Newfoundland"
            | "Canada/Pacific"
            | "Canada/Saskatchewan"
            | "Canada/Yukon"
      • Optionalutc?: boolean

    Returns string

diff --git a/docs/functions/formatNumber.html b/docs/functions/formatNumber.html index a98ace7f..76c9bfe6 100644 --- a/docs/functions/formatNumber.html +++ b/docs/functions/formatNumber.html @@ -1,4 +1,4 @@ -formatNumber | Journalism - v1.15.0

Function formatNumber

  • Format a number with a specific style.

    +formatNumber | Journalism - v1.15.1

    Function formatNumber

    • Format a number with a specific style.

      const string = formatNumber(1234.567, { sign: true, round: true })
      // returns "+1,235"
      @@ -14,4 +14,4 @@
    • prefix: a string to add before the number, "$" for example
    • suffix: a string to add after the number, "%" for example
    -

    Parameters

    • number: number
    • options: {
          decimals?: number;
          fixed?: boolean;
          nearestInteger?: number;
          prefix?: string;
          round?: boolean;
          sign?: boolean;
          significantDigits?: number;
          style?: "cbc" | "rc";
          suffix?: string;
      } = {}
      • Optionaldecimals?: number
      • Optionalfixed?: boolean
      • OptionalnearestInteger?: number
      • Optionalprefix?: string
      • Optionalround?: boolean
      • Optionalsign?: boolean
      • OptionalsignificantDigits?: number
      • Optionalstyle?: "cbc" | "rc"
      • Optionalsuffix?: string

    Returns string

+

Parameters

Returns string

diff --git a/docs/functions/geoTo3D.html b/docs/functions/geoTo3D.html index 3f1a5c1f..4bfa7743 100644 --- a/docs/functions/geoTo3D.html +++ b/docs/functions/geoTo3D.html @@ -1,6 +1,6 @@ -geoTo3D | Journalism - v1.15.0

Function geoTo3D

  • Convert longitude and latitude to x,y,z coordinates based on a given radius. The options (last parameter) are optional.

    +geoTo3D | Journalism - v1.15.1

    Function geoTo3D

    • Convert longitude and latitude to x,y,z coordinates based on a given radius. The options (last parameter) are optional.

      const coords = geoTo3D(-73.5674, 45.5019, 1, { decimals: 2})
      // returns { x: -0.67, y: 0.71, z: 0.2 }

      You can pass { toArray: true } to return an array instead of an object.

      -

      Parameters

      • lon: number
      • lat: number
      • radius: number
      • options: {
            decimals?: number;
            toArray?: boolean;
        } = {}
        • Optionaldecimals?: number
        • OptionaltoArray?: boolean

      Returns {
          x: number;
          y: number;
          z: number;
      } | [number, number, number]

    +

    Parameters

    • lon: number
    • lat: number
    • radius: number
    • options: {
          decimals?: number;
          toArray?: boolean;
      } = {}
      • Optionaldecimals?: number
      • OptionaltoArray?: boolean

    Returns {
        x: number;
        y: number;
        z: number;
    } | [number, number, number]

diff --git a/docs/functions/getClosest.html b/docs/functions/getClosest.html index cbc2194c..ddf2d0aa 100644 --- a/docs/functions/getClosest.html +++ b/docs/functions/getClosest.html @@ -1,5 +1,5 @@ -getClosest | Journalism - v1.15.0

Function getClosest

  • Return the closest item of a list based on longitude and latitude. The options (last parameter) are optional. If addDistance is true and geoItems have a properties key, the distance will be added to the properties.

    +getClosest | Journalism - v1.15.1

    Function getClosest

    • Return the closest item of a list based on longitude and latitude. The options (last parameter) are optional. If addDistance is true and geoItems have a properties key, the distance will be added to the properties.

      const geoItems = [
      {name: "Montreal", lon: -73.66, lat: 45.51 },
      {name: "Toronto", lon: -79.43, lat: 43.66 },
      ]
      const ottawa = {lat: 45.37, lon: -75.71}
      const closest = getClosest(
      ottawa.lon,
      ottawa.lat,
      geoItems,
      d => d.lon,
      d => d.lat,
      { addDistance: true, decimals: 3 }
      )
      // return { name: "Montreal", lon: -73.66, lat: 45.51, distance: 160.694 }
      -

      Parameters

      • lon: number
      • lat: number
      • geoItems: unknown[]
      • getItemLon: ((d: unknown) => number)
          • (d): number
          • Parameters

            • d: unknown

            Returns number

      • getItemLat: ((d: unknown) => number)
          • (d): number
          • Parameters

            • d: unknown

            Returns number

      • options: {
            addDistance?: boolean;
            decimals?: number;
        } = {}
        • OptionaladdDistance?: boolean
        • Optionaldecimals?: number

      Returns {
          distance?: number;
          properties?: {
              distance?: number;
          };
      }

      • Optionaldistance?: number
      • Optionalproperties?: {
            distance?: number;
        }
        • Optionaldistance?: number
    +

    Parameters

    • lon: number
    • lat: number
    • geoItems: unknown[]
    • getItemLon: ((d: unknown) => number)
        • (d): number
        • Parameters

          • d: unknown

          Returns number

    • getItemLat: ((d: unknown) => number)
        • (d): number
        • Parameters

          • d: unknown

          Returns number

    • options: {
          addDistance?: boolean;
          decimals?: number;
      } = {}
      • OptionaladdDistance?: boolean
      • Optionaldecimals?: number

    Returns {
        distance?: number;
        properties?: {
            distance?: number;
        };
    }

    • Optionaldistance?: number
    • Optionalproperties?: {
          distance?: number;
      }
      • Optionaldistance?: number
diff --git a/docs/functions/getCovarianceMatrix.html b/docs/functions/getCovarianceMatrix.html index 743e10f5..53710e9d 100644 --- a/docs/functions/getCovarianceMatrix.html +++ b/docs/functions/getCovarianceMatrix.html @@ -1,2 +1,2 @@ -getCovarianceMatrix | Journalism - v1.15.0

Function getCovarianceMatrix

  • Computes the covariance matrix, with an option to invert it.

    -

    Parameters

    • data: number[][]
    • options: {
          invert?: boolean;
      } = {}
      • Optionalinvert?: boolean

    Returns number[][]

+getCovarianceMatrix | Journalism - v1.15.1

Function getCovarianceMatrix

  • Computes the covariance matrix, with an option to invert it.

    +

    Parameters

    • data: number[][]
    • options: {
          invert?: boolean;
      } = {}
      • Optionalinvert?: boolean

    Returns number[][]

diff --git a/docs/functions/getGeoTiffDetails.html b/docs/functions/getGeoTiffDetails.html index 7ff23786..d45a215b 100644 --- a/docs/functions/getGeoTiffDetails.html +++ b/docs/functions/getGeoTiffDetails.html @@ -1,5 +1,5 @@ -getGeoTiffDetails | Journalism - v1.15.0

Function getGeoTiffDetails

  • Extracts detailed informations from a geoTIFF that can be used with the getGeoTiffValues function. Just for NodeJS and similar runtimes.

    +getGeoTiffDetails | Journalism - v1.15.1

    Function getGeoTiffDetails

    • Extracts detailed informations from a geoTIFF that can be used with the getGeoTiffValues function. Just for NodeJS and similar runtimes.

      const geoTiffDetails = await getGeoTiffDetails("./some-file.tif")
      const value = await getGeoTiffValues(45.50, -73.57, geoTiffDetails)
      -

      Parameters

      • path: string

      Returns Promise<{
          bbox: number[];
          bboxHeight: number;
          bboxWidth: number;
          image: GeoTIFFImage;
          pixelHeight: number;
          pixelWidth: number;
      }>

    +

    Parameters

    • path: string

    Returns Promise<{
        bbox: number[];
        bboxHeight: number;
        bboxWidth: number;
        image: GeoTIFFImage;
        pixelHeight: number;
        pixelWidth: number;
    }>

diff --git a/docs/functions/getGeoTiffValues.html b/docs/functions/getGeoTiffValues.html index 5f313a60..40287803 100644 --- a/docs/functions/getGeoTiffValues.html +++ b/docs/functions/getGeoTiffValues.html @@ -1,5 +1,5 @@ -getGeoTiffValues | Journalism - v1.15.0

Function getGeoTiffValues

  • Extracts values at specific lat/lon coordinates from a geotiff. Works with the values returned by the getGeoTiffDetails function.

    +getGeoTiffValues | Journalism - v1.15.1

    Function getGeoTiffValues

    • Extracts values at specific lat/lon coordinates from a geotiff. Works with the values returned by the getGeoTiffDetails function.

      const geoTiffDetails = await getGeoTiffDetails("./some-file.tif")
      const value = await getGeoTiffValues(45.50, -73.57, geoTiffDetails)
      -

      Parameters

      • lat: number
      • lon: number
      • __namedParameters: {
            bbox: number[];
            bboxHeight: number;
            bboxWidth: number;
            image: GeoTIFFImage;
            pixelHeight: number;
            pixelWidth: number;
        }
        • bbox: number[]
        • bboxHeight: number
        • bboxWidth: number
        • image: GeoTIFFImage
        • pixelHeight: number
        • pixelWidth: number

      Returns Promise<TypedArray>

    +

    Parameters

    • lat: number
    • lon: number
    • __namedParameters: {
          bbox: number[];
          bboxHeight: number;
          bboxWidth: number;
          image: GeoTIFFImage;
          pixelHeight: number;
          pixelWidth: number;
      }
      • bbox: number[]
      • bboxHeight: number
      • bboxWidth: number
      • image: GeoTIFFImage
      • pixelHeight: number
      • pixelWidth: number

    Returns Promise<TypedArray>

diff --git a/docs/functions/getHtmlTable.html b/docs/functions/getHtmlTable.html index 217f7cf9..682b1b25 100644 --- a/docs/functions/getHtmlTable.html +++ b/docs/functions/getHtmlTable.html @@ -1,5 +1,5 @@ -getHtmlTable | Journalism - v1.15.0

Function getHtmlTable

  • Returns the data from an HTML table as an array of objects. The first parameter is an url. The second parameter is an optional object specifying a css selector and/or an index.

    +getHtmlTable | Journalism - v1.15.1

    Function getHtmlTable

    • Returns the data from an HTML table as an array of objects. The first parameter is an url. The second parameter is an optional object specifying a css selector and/or an index.

      // This would parse the data from the fourth
      // table with the class name data-table.
      const data = await getHtmlTable("your-url-here", {
      selector: ".data-table",
      index: 3
      })
      -

      Parameters

      • url: string
      • options: {
            index?: number;
            selector?: string;
        } = {}
        • Optionalindex?: number
        • Optionalselector?: string

      Returns Promise<DSVRowArray<string>>

    +

    Parameters

    • url: string
    • options: {
          index?: number;
          selector?: string;
      } = {}
      • Optionalindex?: number
      • Optionalselector?: string

    Returns Promise<DSVRowArray<string>>

diff --git a/docs/functions/getHumidex.html b/docs/functions/getHumidex.html index ae57f4e3..dcd89632 100644 --- a/docs/functions/getHumidex.html +++ b/docs/functions/getHumidex.html @@ -1,7 +1,7 @@ -getHumidex | Journalism - v1.15.0

Function getHumidex

  • Calculate Humidex Factor in Celsius given the temperature in Celsius and humidity percentage. +getHumidex | Journalism - v1.15.1

    Function getHumidex

    • Calculate Humidex Factor in Celsius given the temperature in Celsius and humidity percentage. In case the calculated humidex is less than the given temperature, it returns temperature itself.

      const humidex = getHumidex(30, 70); // returns 41
       

      This is using the formula from the Canadian Centre for Climate Services.

      -

      Parameters

      • temperature: number
      • humidity: number

      Returns number

    +

    Parameters

    • temperature: number
    • humidity: number

    Returns number

diff --git a/docs/functions/getId.html b/docs/functions/getId.html index 357b2390..5ffe1133 100644 --- a/docs/functions/getId.html +++ b/docs/functions/getId.html @@ -1,2 +1,2 @@ -getId | Journalism - v1.15.0

Function getId

  • Creates a unique id with letters, numbers, but no spaces or special characters. By default, the length is 6 characters. Works in the browser and NodeJS (and other runtimes). Handy, but not cryptographically secure.

    -

    Parameters

    • length: number = 6

    Returns string

+getId | Journalism - v1.15.1

Function getId

  • Creates a unique id with letters, numbers, but no spaces or special characters. By default, the length is 6 characters. Works in the browser and NodeJS (and other runtimes). Handy, but not cryptographically secure.

    +

    Parameters

    • length: number = 6

    Returns string

diff --git a/docs/functions/getMahalanobisDistance.html b/docs/functions/getMahalanobisDistance.html index 25736d96..ac69d08d 100644 --- a/docs/functions/getMahalanobisDistance.html +++ b/docs/functions/getMahalanobisDistance.html @@ -1,2 +1,2 @@ -getMahalanobisDistance | Journalism - v1.15.0

Function getMahalanobisDistance

  • Computes the Mahalanobis distance. You first need to compute the inverted covariance matrix of your data with getCovarianceMatrix.

    -

    Parameters

    • x1: number[]
    • x2: number[]
    • invCovMatrix: number[][]

    Returns number

+getMahalanobisDistance | Journalism - v1.15.1

Function getMahalanobisDistance

  • Computes the Mahalanobis distance. You first need to compute the inverted covariance matrix of your data with getCovarianceMatrix.

    +

    Parameters

    • x1: number[]
    • x2: number[]
    • invCovMatrix: number[][]

    Returns number

diff --git a/docs/functions/getSeason.html b/docs/functions/getSeason.html index 0179c446..af730a53 100644 --- a/docs/functions/getSeason.html +++ b/docs/functions/getSeason.html @@ -1,2 +1,2 @@ -getSeason | Journalism - v1.15.0

Function getSeason

  • Determines the current season based on a date (current date by default). Options include hemisphere (northern by default) and type (astronomical by default).

    -

    Parameters

    • options: {
          date?: Date;
          hemisphere?: "northern" | "southern";
          type?: "meteorological" | "astronomical";
      } = {}
      • Optionaldate?: Date
      • Optionalhemisphere?: "northern" | "southern"
      • Optionaltype?: "meteorological" | "astronomical"

    Returns
        | "winter"
        | "spring"
        | "summer"
        | "fall"

+getSeason | Journalism - v1.15.1

Function getSeason

  • Determines the current season based on a date (current date by default). Options include hemisphere (northern by default) and type (astronomical by default).

    +

    Parameters

    • options: {
          date?: Date;
          hemisphere?: "northern" | "southern";
          type?: "meteorological" | "astronomical";
      } = {}
      • Optionaldate?: Date
      • Optionalhemisphere?: "northern" | "southern"
      • Optionaltype?: "meteorological" | "astronomical"

    Returns
        | "winter"
        | "spring"
        | "summer"
        | "fall"

diff --git a/docs/functions/getSheetData.html b/docs/functions/getSheetData.html index ae1b9ec2..d2b12401 100644 --- a/docs/functions/getSheetData.html +++ b/docs/functions/getSheetData.html @@ -1,4 +1,4 @@ -getSheetData | Journalism - v1.15.0

Function getSheetData

  • Returns the data of a Google Sheet.

    +getSheetData | Journalism - v1.15.1

    Function getSheetData

    • Returns the data of a Google Sheet.

      By default, this function looks for the API key in process.env.GOOGLE_PRIVATE_KEY and the service account email in process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL. If you don't have credentials, check this.

      // Fake url used as an example.
      const sheetUrl = "https://docs.google.com/spreadsheets/d/nrqo3oP4KMWYbELScQa8W1nHZPfIrA7LIz9UmcRE4GyJN/edit#gid=0";

      // Returning the data as an array of objects.
      const data = await getSheetData(data, sheetUrl);

      // Same but skipping first row.
      const data = await getSheetData(data, sheetUrl, { skip: 1});

      // You have an option to return the data as a CSV string. Useful if you just want to write the data somewhere.
      const csv = await getSheetData(data, sheetUrl, { csv: true });

      // If your API email and key are stored under different names in process.env, use the options.
      const csv = await getSheetData(data, sheetUrl, { apiEmail: "GG_EMAIL", apiKey: "GG_KEY" });
      @@ -9,4 +9,4 @@
    • OptionalapiKey?: string

      If your API key is stored under different names in process.env, use this option.

    • Optionalcsv?: boolean

      If true, the function will return a CSV string instead of an array of objects.

    • Optionalskip?: number

      The number of rows to skip before parsing the data. Defaults to 0.

      -

Returns Promise<string | DSVRowArray<string>>

+

Returns Promise<string | DSVRowArray<string>>

diff --git a/docs/functions/getStatCanTable.html b/docs/functions/getStatCanTable.html index c9578ecf..3f6ae083 100644 --- a/docs/functions/getStatCanTable.html +++ b/docs/functions/getStatCanTable.html @@ -1,4 +1,4 @@ -getStatCanTable | Journalism - v1.15.0

Function getStatCanTable

  • Returns the data from a Statistics Canada table as an array of objects. The first parameter is the pid value that can be found in the table url. The second parameter is an optional object specifying:

    +getStatCanTable | Journalism - v1.15.1

    Function getStatCanTable

    • Returns the data from a Statistics Canada table as an array of objects. The first parameter is the pid value that can be found in the table url. The second parameter is an optional object specifying:

      • the language
      • if the first character of the file should be skipped (sometimes the files are weirdly formatted)
      • @@ -7,4 +7,4 @@
        const data = await getStatCanTable('98100001')
         
        -

      Parameters

      • pid: string
      • options: {
            debug?: boolean;
            lang?: "en" | "fr";
            returnRawCSV?: boolean;
            skipFirstCharacter?: boolean;
        } = {}
        • Optionaldebug?: boolean
        • Optionallang?: "en" | "fr"
        • OptionalreturnRawCSV?: boolean
        • OptionalskipFirstCharacter?: boolean

      Returns Promise<string | DSVRowArray<string>>

    +

    Parameters

    • pid: string
    • options: {
          debug?: boolean;
          lang?: "en" | "fr";
          returnRawCSV?: boolean;
          skipFirstCharacter?: boolean;
      } = {}
      • Optionaldebug?: boolean
      • Optionallang?: "en" | "fr"
      • OptionalreturnRawCSV?: boolean
      • OptionalskipFirstCharacter?: boolean

    Returns Promise<string | DSVRowArray<string>>

diff --git a/docs/functions/invertMatrix.html b/docs/functions/invertMatrix.html index 28942511..5af767fa 100644 --- a/docs/functions/invertMatrix.html +++ b/docs/functions/invertMatrix.html @@ -1,2 +1,2 @@ -invertMatrix | Journalism - v1.15.0

Function invertMatrix

  • Computes the invert of a square matrix.

    -

    Parameters

    • matrix: number[][]

    Returns number[][]

+invertMatrix | Journalism - v1.15.1

Function invertMatrix

  • Computes the invert of a square matrix.

    +

    Parameters

    • matrix: number[][]

    Returns number[][]

diff --git a/docs/functions/mortgageInsurancePremium.html b/docs/functions/mortgageInsurancePremium.html index 14323c08..15a82b4c 100644 --- a/docs/functions/mortgageInsurancePremium.html +++ b/docs/functions/mortgageInsurancePremium.html @@ -1,7 +1,7 @@ -mortgageInsurancePremium | Journalism - v1.15.0

Function mortgageInsurancePremium

  • Calculates the mortgage insurance premium based on the property value and down payment. The returned value is rounded to the nearest integer. Based on the Financial Consumer Agency of Canada calculator.

    +mortgageInsurancePremium | Journalism - v1.15.1

    Function mortgageInsurancePremium

    • Calculates the mortgage insurance premium based on the property value and down payment. The returned value is rounded to the nearest integer. Based on the Financial Consumer Agency of Canada calculator.

      // Returns 19_000
      const insurancePremium = mortgageInsurancePremium(500_000, 25_000)

      Parameters

      • purchasePrice: number

        The price of the purchased property.

      • downPayment: number

        The amount of money paid upfront.

        -

      Returns number

    +

Returns number

diff --git a/docs/functions/mortgageMaxAmount.html b/docs/functions/mortgageMaxAmount.html index 45ff977c..67ac7ed4 100644 --- a/docs/functions/mortgageMaxAmount.html +++ b/docs/functions/mortgageMaxAmount.html @@ -1,4 +1,4 @@ -mortgageMaxAmount | Journalism - v1.15.0

Function mortgageMaxAmount

  • Calculates the maximum purchase price (and other variables) for a property a person can afford and the related mortgage it would qualify for based on annual income, down payment, mortgage interest rate, and additional options.

    +mortgageMaxAmount | Journalism - v1.15.1

    Function mortgageMaxAmount

    • Calculates the maximum purchase price (and other variables) for a property a person can afford and the related mortgage it would qualify for based on annual income, down payment, mortgage interest rate, and additional options.

      // With an annual income of $100,000, a down payment of $25,000, and a rate of 5.25%.
      const results = maxMortgageAmount(100_000, 25_000, 5.25)
      // results = {
      // annualIncome: 100000,
      // downPayment: 25000,
      // rate: 5.25,
      // rateTested: 7.25,
      // purchasePrice: 307000,
      // mortgageAmount: 293280,
      // insurancePremium: 11280,
      // monthlyMortgagePayment: 2099.65,
      // grossDebtServiceRatio: 0.32,
      // totalDebtServiceRatio: 0.32,
      // reason: "debt limit",
      // monthlyDebtPayment: 0,
      // monthlyHeating: 175,
      // isHeatingEstimate: true,
      // monthlyTax: 385,
      // isTaxEstimate: true,
      // monthlyCondoFees: 0,
      // }
      @@ -10,4 +10,4 @@
    • OptionalmonthlyDebtPayment?: number

      The monthly debt payment of the borrower. Defaults to 0.

    • OptionalmonthlyHeating?: number

      The monthly heating cost. Defaults to $175.

    • OptionalmonthlyTax?: number

      The monthly property tax. Default to 1.5% of the purchase price.

      -

Returns {
    annualIncome: number;
    downPayment: number;
    grossDebtServiceRatio: number;
    insurancePremium: number;
    isHeatingEstimate: boolean;
    isTaxEstimate: boolean;
    monthlyCondoFees: number;
    monthlyDebtPayment: number;
    monthlyHeating: number;
    monthlyMortgagePayment: number;
    monthlyTax: number;
    mortgageAmount: number;
    purchasePrice: number;
    rate: number;
    rateTested: number;
    reason: string;
    totalDebtServiceRatio: number;
}

+

Returns {
    annualIncome: number;
    downPayment: number;
    grossDebtServiceRatio: number;
    insurancePremium: number;
    isHeatingEstimate: boolean;
    isTaxEstimate: boolean;
    monthlyCondoFees: number;
    monthlyDebtPayment: number;
    monthlyHeating: number;
    monthlyMortgagePayment: number;
    monthlyTax: number;
    mortgageAmount: number;
    purchasePrice: number;
    rate: number;
    rateTested: number;
    reason: string;
    totalDebtServiceRatio: number;
}

diff --git a/docs/functions/mortgagePayments.html b/docs/functions/mortgagePayments.html index aec5c8fc..50e2ea1c 100644 --- a/docs/functions/mortgagePayments.html +++ b/docs/functions/mortgagePayments.html @@ -1,4 +1,4 @@ -mortgagePayments | Journalism - v1.15.0

Function mortgagePayments

  • Returns fixed rate mortgage payments in an array. Each payment is an object with the paymentId, the payment amount, the interest and capital portions of the payment, the remaining mortgage balance, and the total amount paid, total interest paid, and total capital reimbursed so far. The calculations have been tested for Canada, which requires fixed rate mortgages to be compounded semi-annually by law. But you can change the annualCompounding in the options.

    +mortgagePayments | Journalism - v1.15.1

    Function mortgagePayments

    • Returns fixed rate mortgage payments in an array. Each payment is an object with the paymentId, the payment amount, the interest and capital portions of the payment, the remaining mortgage balance, and the total amount paid, total interest paid, and total capital reimbursed so far. The calculations have been tested for Canada, which requires fixed rate mortgages to be compounded semi-annually by law. But you can change the annualCompounding in the options.

      If the amortizationPeriod is smaller than the term, an error is thrown.

      These options can be passed in an object as the last parameter:

        @@ -8,4 +8,4 @@
      • debug: Will log extra information if true.

      Calculations are based on https://www.yorku.ca/amarshal/mortgage.htm and https://www.mikesukmanowsky.com/blog/a-guide-to-canadian-mortgage-calculations

      -

      Parameters

      • mortageAmount: number
      • rate: number
      • paymentFrequency:
            | "weekly"
            | "biWeekly"
            | "monthly"
            | "semiMonthly"
            | "acceleratedWeekly"
            | "acceleratedBiWeekly"
      • term: number
      • amortizationPeriod: number
      • options: {
            annualCompounding?: number;
            debug?: boolean;
            decimals?: number;
            id?: string;
        } = {}
        • OptionalannualCompounding?: number
        • Optionaldebug?: boolean
        • Optionaldecimals?: number
        • Optionalid?: string

      Returns {
          amountPaid: number;
          balance: number;
          capital: number;
          capitalPaid: number;
          id?: string;
          interest: number;
          interestPaid: number;
          payment: number;
          paymentId: number;
      }[]

    +

    Parameters

    • mortageAmount: number
    • rate: number
    • paymentFrequency:
          | "weekly"
          | "biWeekly"
          | "monthly"
          | "semiMonthly"
          | "acceleratedWeekly"
          | "acceleratedBiWeekly"
    • term: number
    • amortizationPeriod: number
    • options: {
          annualCompounding?: number;
          debug?: boolean;
          decimals?: number;
          id?: string;
      } = {}
      • OptionalannualCompounding?: number
      • Optionaldebug?: boolean
      • Optionaldecimals?: number
      • Optionalid?: string

    Returns {
        amountPaid: number;
        balance: number;
        capital: number;
        capitalPaid: number;
        id?: string;
        interest: number;
        interestPaid: number;
        payment: number;
        paymentId: number;
    }[]

diff --git a/docs/functions/overwriteSheetData.html b/docs/functions/overwriteSheetData.html index dbb0385b..66f19848 100644 --- a/docs/functions/overwriteSheetData.html +++ b/docs/functions/overwriteSheetData.html @@ -1,4 +1,4 @@ -overwriteSheetData | Journalism - v1.15.0

Function overwriteSheetData

  • Clears a Google Sheet and populates it with new data.

    +overwriteSheetData | Journalism - v1.15.1

    Function overwriteSheetData

    • Clears a Google Sheet and populates it with new data.

      By default, this function looks for the API key in process.env.GOOGLE_PRIVATE_KEY and the service account email in process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL. If you don't have credentials, check this.

      // The data needs to be an array of objects. The keys of the first object will be used to create the header row.
      const data = [
      { first: "Nael", last: "Shiab" },
      { first: "Andrew", last: "Ryan" },
      ];
      // Fake url used as an example.
      const sheetUrl = "https://docs.google.com/spreadsheets/d/nrqo3oP4KMWYbELScQa8W1nHZPfIrA7LIz9UmcRE4GyJN/edit#gid=0";

      // Clearing the sheet and then populating it.
      await overwriteSheetData(data, sheetUrl);

      // Same thing but with raw values. Google Sheet won't try to guess the data types and won't format or parse the values.
      await overwriteSheetData(data, sheetUrl, { raw: true });

      // Adding the UTC date of the update before the data.
      await overwriteSheetData(data, sheetUrl, { lastUpdate: true });

      // You can also format the date to a specific time zone.
      await overwriteSheetData(data, sheetUrl, { lastUpdate: true, timeZone: "Canada/Eastern" });

      // The prepend option allows you to add extra text on the first row.
      await overwriteSheetData(data, sheetUrl, { prepend: "Contact xxxx.xxxx@gmail.com for more information", lastUpdate: true, timeZone: "Canada/Eastern" });

      // If your API email and key are stored under different names in process.env, use the options.
      await overwriteSheetData(data, sheetUrl, { apiEmail: "GG_EMAIL", apiKey: "GG_KEY" });
      @@ -12,4 +12,4 @@
    • Optionalprepend?: string

      Text to be added before the data.

    • Optionalraw?: boolean

      If true, Google Sheet won't try to guess the data type and won't format or parse the values.

    • OptionaltimeZone?:
          | "Canada/Atlantic"
          | "Canada/Central"
          | "Canada/Eastern"
          | "Canada/Mountain"
          | "Canada/Newfoundland"
          | "Canada/Pacific"
          | "Canada/Saskatchewan"
          | "Canada/Yukon"

      If lastUpdate is true, you can use this option to format the date to a specific time zone.

      -

Returns Promise<void>

+

Returns Promise<void>

diff --git a/docs/functions/prettyDuration.html b/docs/functions/prettyDuration.html index cf114b5d..87282a97 100644 --- a/docs/functions/prettyDuration.html +++ b/docs/functions/prettyDuration.html @@ -1,5 +1,5 @@ -prettyDuration | Journalism - v1.15.0

Function prettyDuration

  • Returns the duration as a string in terms of milliseconds, seconds, minutes, hours, and days.

    +prettyDuration | Journalism - v1.15.1

    Function prettyDuration

    • Returns the duration as a string in terms of milliseconds, seconds, minutes, hours, and days.

      // A starting Date somewhere in your code
      const startDate = new Date() // or Date.now()

      // When you want to know the elapsed duration, pass the start date
      const duration = prettyDuration(startDate)
      // Returns something like "22 days, 6 h, 3 min, 15 sec, 3 ms"

      // If you want to console.log it, set the option log to true
      prettyDuration(startDate, {log: true})

      // You can also use a prefix and/or suffix
      prettyDuration(startDate, {log: true, prefix: "Total duration: ", suffix: " (Main function)"})
      // Returns and logs something like "Total duration: 3 min, 15 sec, 3 ms (Main function)"

      // If you want to format the duration between two specific dates, use the end option.
      prettyDuration(new Date("2024-01-01T17:00:00"), { end: new Date("2024-01-23T23:03:15") })
      // Returns "22 days, 6 h, 3 min, 15 sec, 0 ms"
      -

      Parameters

      • start: number | Date
      • options: {
            end?: number | Date;
            log?: boolean;
            prefix?: string;
            suffix?: string;
        } = {}
        • Optionalend?: number | Date
        • Optionallog?: boolean
        • Optionalprefix?: string
        • Optionalsuffix?: string

      Returns string

    +

    Parameters

    • start: number | Date
    • options: {
          end?: number | Date;
          log?: boolean;
          prefix?: string;
          suffix?: string;
      } = {}
      • Optionalend?: number | Date
      • Optionallog?: boolean
      • Optionalprefix?: string
      • Optionalsuffix?: string

    Returns string

diff --git a/docs/functions/publishChartDW.html b/docs/functions/publishChartDW.html index 7a3b3497..81c5152b 100644 --- a/docs/functions/publishChartDW.html +++ b/docs/functions/publishChartDW.html @@ -1,5 +1,5 @@ -publishChartDW | Journalism - v1.15.0

Function publishChartDW

  • Publishes the specified Datawrapper chart, table, or map. By default, this function looks for the API key in process.env.DATAWRAPPER_KEY.

    +publishChartDW | Journalism - v1.15.1

    Function publishChartDW

    • Publishes the specified Datawrapper chart, table, or map. By default, this function looks for the API key in process.env.DATAWRAPPER_KEY.

      const chartID = "myChartId"
      await publishChartDW(chartID)

      // If your API key is stored under a different name in process.env, use the options.
      await publishChartDW(chartID, { apiKey: "DW_KEY" })
      -

      Parameters

      • chartId: string
      • options: {
            apiKey?: string;
            returnResponse?: boolean;
        } = {}
        • OptionalapiKey?: string
        • OptionalreturnResponse?: boolean

      Returns Promise<void | Response>

    +

    Parameters

    • chartId: string
    • options: {
          apiKey?: string;
          returnResponse?: boolean;
      } = {}
      • OptionalapiKey?: string
      • OptionalreturnResponse?: boolean

    Returns Promise<void | Response>

diff --git a/docs/functions/round.html b/docs/functions/round.html index 690822cc..c12095e6 100644 --- a/docs/functions/round.html +++ b/docs/functions/round.html @@ -1,4 +1,4 @@ -round | Journalism - v1.15.0

Function round

  • Round a number. By default, round to the nearest integer.

    +round | Journalism - v1.15.1

    Function round

    • Round a number. By default, round to the nearest integer.

      const string = round(1234.567, { decimals: 1 })
      // returns 1,235.6
      @@ -9,4 +9,4 @@
    • significantDigits: The number of digits to keep. Significant digits start being counted at the first non-zero digit. For example, 0.004622 with 1 significant digit will the rounded to 0.005.
    • try: by default, the function throws an error if the passed value is not a number. With try set to true, no error is thrown but the returned value is NaN.
    -

    Parameters

    • number: number
    • options: {
          decimals?: number;
          nearestInteger?: number;
          significantDigits?: number;
          try?: boolean;
      } = {}
      • Optionaldecimals?: number
      • OptionalnearestInteger?: number
      • OptionalsignificantDigits?: number
      • Optionaltry?: boolean

    Returns number

+

Parameters

Returns number

diff --git a/docs/functions/savePlotChart.html b/docs/functions/savePlotChart.html index 4ed412ec..869b04ec 100644 --- a/docs/functions/savePlotChart.html +++ b/docs/functions/savePlotChart.html @@ -1,5 +1,5 @@ -savePlotChart | Journalism - v1.15.0

Function savePlotChart

  • Saves an Observable Plot chart as an image. You must use the Plot.dot syntax and install puppeteer (npm i puppeteer).

    +savePlotChart | Journalism - v1.15.1

    Function savePlotChart

    • Saves an Observable Plot chart as an image. You must use the Plot.dot syntax and install puppeteer (npm i puppeteer).

      import * as Plot from "@observablehq/plot"

      // The data must be an array of objects.
      const data = [{ salary: 75000, hireDate: new Date("2023-12-22") }, ...]

      // The Plot options must be wrapped into a function and use the Plot. syntax.
      const chart = () => Plot.plot({
      marks: [
      Plot.dot(data, {x: "hireDate", y: "salary"})
      ]
      })

      // Change the extension to .jpeg to get a JPEG file.
      const path = "./my-chart.png"

      await savePlotChart(data, chart, path)
      -

      Parameters

      • data: {
            [key: string]: unknown;
        }[]
      • makeChart: ((data: {
            [key: string]: unknown;
        }[]) => SVGSVGElement | HTMLElement)
          • (data): SVGSVGElement | HTMLElement
          • Parameters

            • data: {
                  [key: string]: unknown;
              }[]

            Returns SVGSVGElement | HTMLElement

      • path: string

      Returns Promise<void>

    +

    Parameters

    • data: {
          [key: string]: unknown;
      }[]
    • makeChart: ((data: {
          [key: string]: unknown;
      }[]) => SVGSVGElement | HTMLElement)
        • (data): SVGSVGElement | HTMLElement
        • Parameters

          • data: {
                [key: string]: unknown;
            }[]

          Returns SVGSVGElement | HTMLElement

    • path: string

    Returns Promise<void>

diff --git a/docs/functions/styledLayerDescriptor.html b/docs/functions/styledLayerDescriptor.html index 2b59b994..d6c79eb7 100644 --- a/docs/functions/styledLayerDescriptor.html +++ b/docs/functions/styledLayerDescriptor.html @@ -1,5 +1,5 @@ -styledLayerDescriptor | Journalism - v1.15.0

Function styledLayerDescriptor

  • Returns the OpenGIS Styled Layer Descriptor encoded for an URL. The required parameters are the layer and the color scale.

    +styledLayerDescriptor | Journalism - v1.15.1

    Function styledLayerDescriptor

    • Returns the OpenGIS Styled Layer Descriptor encoded for an URL. The required parameters are the layer and the color scale.

      // Returns the SLD for the GDPS.ETA_TT layer with a color scale going from blue to red.
      const sdl = styledLayerDescriptor("GDPS.ETA_TT", [
      { color: "#550c24", value: 100 },
      { color: "#7f2e34", value: 30 },
      { color: "#c26847", value: 20 },
      { color: "#bdbb7a", value: 10 },
      { color: "#e0e9f0", value: 0 },
      { color: "#97b4cd", value: -10 },
      { color: "#5881a1", value: -20 },
      { color: "#334f60", value: -30 },
      { color: "#21353f", value: -100 },
      ])

      // The sdl can now be used in a WMS request as SLD_BODY
      const url = `https://geo.weather.gc.ca/geomet?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=-90,-180,90,180&CRS=EPSG:4326&WIDTH=2400&HEIGHT=1200&LAYERS=GDPS.ETA_TT&FORMAT=image/jpeg&SLD_BODY=${sld}`
      -

      Parameters

      • layer: string
      • colorScale: {
            color: string;
            value: number;
        }[]

      Returns string

    +

    Parameters

    • layer: string
    • colorScale: {
          color: string;
          value: number;
      }[]

    Returns string

diff --git a/docs/functions/unzip.html b/docs/functions/unzip.html index 9fee79d5..e592edcd 100644 --- a/docs/functions/unzip.html +++ b/docs/functions/unzip.html @@ -1,4 +1,4 @@ -unzip | Journalism - v1.15.0

Function unzip

  • Unzips a file and outputs the result in a folder.

    +unzip | Journalism - v1.15.1

    Function unzip

    • Unzips a file and outputs the result in a folder.

      unzip("files.zip", "./output/")
       
      @@ -6,4 +6,4 @@
      unzip("files.zip", "./output/", { deleteZippedFile: true })
       
      -

      Parameters

      • zippedFile: string
      • output: string
      • options: {
            deleteZippedFile?: boolean;
        } = {}
        • OptionaldeleteZippedFile?: boolean

      Returns void

    +

    Parameters

    • zippedFile: string
    • output: string
    • options: {
          deleteZippedFile?: boolean;
      } = {}
      • OptionaldeleteZippedFile?: boolean

    Returns void

diff --git a/docs/functions/updateAnnotationsDW.html b/docs/functions/updateAnnotationsDW.html index 8aee840e..776cdc68 100644 --- a/docs/functions/updateAnnotationsDW.html +++ b/docs/functions/updateAnnotationsDW.html @@ -1,5 +1,5 @@ -updateAnnotationsDW | Journalism - v1.15.0

Function updateAnnotationsDW

  • Updates annotations in on a chart. By default, this function looks for the API key in process.env.DATAWRAPPER_KEY.

    +updateAnnotationsDW | Journalism - v1.15.1

    Function updateAnnotationsDW

    • Updates annotations in on a chart. By default, this function looks for the API key in process.env.DATAWRAPPER_KEY.

      import { updateAnnotationsDW } from "journalism"

      const chartID = "myChartId"
      const myAnnotations = [
      {
      "x": "2024/08/30 01:52",
      "y": "14496235",
      "text": "This is an annotation!",
      },
      {
      "x": "2024/06/29",
      "y": "15035128",
      "dy": 50,
      "text": "This is also some text, but with an arrow!",
      "connectorLine": {
      "enabled": true,
      "type": "straight",
      "arrowHead": "lines"
      },
      "mobileFallback": false
      }
      ]

      await updateAnnotationsDW(chartID, myAnnotations)

      // If your API key is stored under a different name in process.env, use the options.
      await updateAnnotationsDW(chartID, myAnnotations, { apiKey: "DW_KEY" })
      -

      Parameters

      • chartId: string
      • annotations: {
            align?:
                | "tr"
                | "tl"
                | "tc"
                | "ml"
                | "mc"
                | "mr"
                | "bl"
                | "bc"
                | "br";
            bg?: boolean;
            bold?: boolean;
            color?: string;
            connectorLine?: {
                arrowHead?: false | "lines" | "triangle";
                circle?: boolean;
                circleRadius?: number;
                circleStyle?: string;
                enabled?: boolean;
                inheritColor?: boolean;
                stroke?: 1 | 3 | 2;
                targetPadding?: number;
                type?: "straight" | "curveRight" | "curveLeft";
            };
            dx?: number;
            dy?: number;
            italic?: boolean;
            mobileFallback?: boolean;
            showDesktop?: boolean;
            showMobile?: boolean;
            size?: number;
            text: string;
            underline?: boolean;
            width?: number;
            x: string;
            y: string;
        }[]
      • options: {
            apiKey?: string;
            returnResponse?: boolean;
        } = {}
        • OptionalapiKey?: string
        • OptionalreturnResponse?: boolean

      Returns Promise<void | Response>

    +

    Parameters

    • chartId: string
    • annotations: {
          align?:
              | "tr"
              | "tl"
              | "tc"
              | "ml"
              | "mc"
              | "mr"
              | "bl"
              | "bc"
              | "br";
          bg?: boolean;
          bold?: boolean;
          color?: string;
          connectorLine?: {
              arrowHead?: false | "lines" | "triangle";
              circle?: boolean;
              circleRadius?: number;
              circleStyle?: string;
              enabled?: boolean;
              inheritColor?: boolean;
              stroke?: 1 | 3 | 2;
              targetPadding?: number;
              type?: "straight" | "curveRight" | "curveLeft";
          };
          dx?: number;
          dy?: number;
          italic?: boolean;
          mobileFallback?: boolean;
          showDesktop?: boolean;
          showMobile?: boolean;
          size?: number;
          text: string;
          underline?: boolean;
          width?: number;
          x: string;
          y: string;
      }[]
    • options: {
          apiKey?: string;
          returnResponse?: boolean;
      } = {}
      • OptionalapiKey?: string
      • OptionalreturnResponse?: boolean

    Returns Promise<void | Response>

diff --git a/docs/functions/updateDataDW.html b/docs/functions/updateDataDW.html index f8eb398e..51c14315 100644 --- a/docs/functions/updateDataDW.html +++ b/docs/functions/updateDataDW.html @@ -1,4 +1,4 @@ -updateDataDW | Journalism - v1.15.0

Function updateDataDW

  • Updates the data of a specified Datawrapper chart, table or map. By default, this function looks for the API key in process.env.DATAWRAPPER_KEY.

    +updateDataDW | Journalism - v1.15.1

    Function updateDataDW

    • Updates the data of a specified Datawrapper chart, table or map. By default, this function looks for the API key in process.env.DATAWRAPPER_KEY.

      Example for a chart.

      import { updateDataDW, dataAsCsv } from "journalism"

      const chartID = "myChartId"

      const data = [
      { salary: 75000, hireDate: new Date("2022-12-15") },
      ...
      ]
      const dataForChart = dataAsCsv(data)

      await updateDataDW(chartID, dataForChart)

      // If your API key is stored under a different name in process.env, use the options.
      await updateDataDW(chartID, dataForChart, { apiKey: "DW_KEY" })
      @@ -7,4 +7,4 @@
      import { updateDataDW } from "journalism"

      const mapID = "myMapId"

      const geojson = {
      "type": "FeatureCollection",
      "features": [
      {
      "type": "Feature",
      "properties": {},
      "geometry": {
      "coordinates": [
      [
      [
      11.127454320325711,
      20.34856592751224
      ],
      [
      11.127454320325711,
      -13.781306861158996
      ],
      [
      55.68071875381875,
      -13.781306861158996
      ],
      [
      55.68071875381875,
      20.34856592751224
      ],
      [
      11.127454320325711,
      20.34856592751224
      ]
      ]
      ],
      "type": "Polygon"
      }
      }
      ]
      }

      const dataForMap = {
      "markers": [
      {
      "id": "m1",
      "type": "area",
      "visible": true,
      "exactShape": true,
      "fill": true,
      "stroke": true,
      "properties": {
      "fill": "#15607a",
      "fill-opacity": 0.2,
      "stroke": "#15607a",
      "stroke-width": 1,
      "stroke-opacity": 1,
      "stroke-dasharray": "100000",
      "pattern": "solid",
      "pattern-line-width": 2,
      "pattern-line-gap": 2
      },
      "feature": geojson
      }
      ]
      }

      await updateDataDW(mapID, JSON.stringify(dataForMap))

      // If your API key is stored under a different name in process.env, use the options.
      await updateDataDW(mapID, JSON.stringify(dataForMap), { apiKey: "DW_KEY" })
      -

      Parameters

      • chartId: string
      • data: string
      • options: {
            apiKey?: string;
            returnResponse?: boolean;
        } = {}
        • OptionalapiKey?: string
        • OptionalreturnResponse?: boolean

      Returns Promise<void | Response>

    +

    Parameters

    • chartId: string
    • data: string
    • options: {
          apiKey?: string;
          returnResponse?: boolean;
      } = {}
      • OptionalapiKey?: string
      • OptionalreturnResponse?: boolean

    Returns Promise<void | Response>

diff --git a/docs/functions/updateNotesDW.html b/docs/functions/updateNotesDW.html index 42e799de..0aebed18 100644 --- a/docs/functions/updateNotesDW.html +++ b/docs/functions/updateNotesDW.html @@ -1,5 +1,5 @@ -updateNotesDW | Journalism - v1.15.0

Function updateNotesDW

  • Updates notes field for a specified Datawrapper chart, table or map. By default, this function looks for the API key in process.env.DATAWRAPPER_KEY.

    +updateNotesDW | Journalism - v1.15.1

    Function updateNotesDW

    • Updates notes field for a specified Datawrapper chart, table or map. By default, this function looks for the API key in process.env.DATAWRAPPER_KEY.

      import { updateNotesDW, formatDate } from "journalism"

      const chartID = "myChartId"
      const dateString = formatDate(new Date(), "Month DD, YYYY, at HH:MM period", { abbreviations: true })
      const note = `This chart was last updated on ${dateString}`

      await updateNotesDW(chartID, note)

      // If your API key is stored under a different name in process.env, use the options.
      await updateNotesDW(chartID, note, { apiKey: "DW_KEY" })
      -

      Parameters

      • chartId: string
      • note: string
      • options: {
            apiKey?: string;
            returnResponse?: boolean;
        } = {}
        • OptionalapiKey?: string
        • OptionalreturnResponse?: boolean

      Returns Promise<void | Response>

    +

    Parameters

    • chartId: string
    • note: string
    • options: {
          apiKey?: string;
          returnResponse?: boolean;
      } = {}
      • OptionalapiKey?: string
      • OptionalreturnResponse?: boolean

    Returns Promise<void | Response>

diff --git a/docs/functions/zip.html b/docs/functions/zip.html index a025676f..0205c82a 100644 --- a/docs/functions/zip.html +++ b/docs/functions/zip.html @@ -1,5 +1,5 @@ -zip | Journalism - v1.15.0

Function zip

  • Zips multiple files together. To zip an entire folder, pass the folder path as the first parameter. To zip specific files, pass their path as an array of strings. The function will create the path of the zipped file if it doesn't exist.

    +zip | Journalism - v1.15.1

    Function zip

    • Zips multiple files together. To zip an entire folder, pass the folder path as the first parameter. To zip specific files, pass their path as an array of strings. The function will create the path of the zipped file if it doesn't exist.

      // Entire folder
      zip("./data", "./data.zip")

      // Specific files
      zip(["./file1.json", "./file2.txt", "./file3.jpg"], "./files.zip")
      -

      Parameters

      • files: string | string[]
      • zipFile: string

      Returns void

    +

    Parameters

    • files: string | string[]
    • zipFile: string

    Returns void

diff --git a/docs/index.html b/docs/index.html index 45f98afa..86c0b36d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,4 +1,4 @@ -Journalism - v1.15.0

Journalism - v1.15.0

Index

Dataviz

publishChartDW +Journalism - v1.15.1

Journalism - v1.15.1

Index

Dataviz

Web scraping

+