Skip to content

Releases: heshansw/simplemap

1.3.1

08 May 14:15

Choose a tag to compare

Reorder Nested Object Array (Available with v1.3.0)

Now you can reorder nested object array on ASC or DESC order and return reordered object in same structure as the original object

  • reOrder Reorder nested object array

    • Parameters

      1. originalObject Original Object
      2. keyPath Nested Key Path to be reordered
      3. SortOrder Sorting Order (SortOrder.ASC for Ascending and SortOrder.DESC for descending)

      Lets say you have this data set

      {
          "schoolName":"Doe School",
          "address":"Stockholm",
          "classes":[
              {
                  "className":"Class 01",
                  "year":"Year 01",
                  "studentData":{
                      "students":[
                      {
                          "studentName":"Philip Larry",
                          "age":16
                      },
                      {
                          "studentName":"John Doe",
                          "age":18
                      },
                      {
                          "studentName":"Alex Numan",
                          "age":15
                      },
                      {
                          "studentName":"Joe Max",
                          "age":20
                      },
                      {
                          "studentName":"Remy Max",
                          "age":21
                      }
                      ]
                  }
              },
              {
                  "className":"Class 02",
                  "year":"Year 01",
                  "studentData":{
                      "students":[
                      {
                          "studentName":"Bale Larry",
                          "age":16
                      },
                      {
                          "studentName":"John Doe",
                          "age":18
                      },
                      {
                          "studentName":"Andersson",
                          "age":15
                      },
                      {
                          "studentName":"Joe Max",
                          "age":20
                      }
                      ]
                  }
              }
          ]
          }

      You can get reordered result by using below method with nested key path to be reordered as the 2nd paramater

      const reordered = reOrder(schoolData, 'classes.studentData.students.studentName')

      So studentName reordered object will look like below

      {
          "schoolName":"Doe School",
          "address":"Stockholm",
          "classes":[
              {
                  "className":"Class 01",
                  "year":"Year 01",
                  "studentData":{
                      "students":[
                      {
                          "studentName":"Alex Numan",
                          "age":15
                      },
                      {
                          "studentName":"Joe Max",
                          "age":20
                      },
                      {
                          "studentName":"John Doe",
                          "age":18
                      },
                      {
                          "studentName":"Philip Larry",
                          "age":16
                      },
                      {
                          "studentName":"Remy Max",
                          "age":21
                      }
                      ]
                  }
              },
              {
                  "className":"Class 02",
                  "year":"Year 01",
                  "studentData":{
                      "students":[
                      {
                          "studentName":"Andersson",
                          "age":15
                      },
                      {
                          "studentName":"Bale Larry",
                          "age":16
                      },
                      {
                          "studentName":"Joe Max",
                          "age":20
                      },
                      {
                          "studentName":"John Doe",
                          "age":18
                      }
                      ]
                  }
              }
          ]
          }

1.3.0

08 May 14:08
b30e102

Choose a tag to compare

Reorder Nested Object Array (Available with v1.3.0)

Now you can reorder nested object array on ASC or DESC order and return reordered object in same structure as the original object

1.2.3

01 Apr 20:52

Choose a tag to compare

Update .npmignore

1.2.2

01 Apr 20:43

Choose a tag to compare

Add Security Note

1.2.1

01 Apr 20:30
29aa8c3

Choose a tag to compare

Improvement with v1.2.1

    With minor version update, you can use new attribute called decimal. If an input field contains attribute **decimal**, form submission will validate input field and if input field contains non decimal value, form submission will trigger an error

    ```html
    <input name="amount" decimal />
    ```

    If there is an error with decimal, you can see error like

    ```json
    { "name": "DECIMAL_ERROR", "message": "amount" }
    ```

    Message will contain error input field name

What's Changed

  • feature - decimal input validator and improved email unit tests by @heshansw in #7

Full Changelog: 1.2.0...1.2.1

1.2.0

28 Mar 19:07

Choose a tag to compare

  • new getFormData method to directly map form data to an object using form submit event
  • email validation will trigger inside getFormData method if there are input type email input fields

Form Value Mappers (Available with v1.2.0)

  • getFormData Can map form data directly to object using this method. If form has an input type with email, this method will use our own validateEmail method and validate the email input value.

    • Parameters

      1. event Submit Event

      Need to pass form Submit event.

      Lets say you have below mentioned form (Please note that this example uses React. But this feature can be used with any framework/library or with vanilla Typescript / Javascript).
      But input name is required

      <form id="formDataModel" onSubmit="{handleSubmit}">
          <input placeholder="name" required name="name" type="text" />
          <input placeholder="email" required name="email" type="email" />
          <input placeholder="grade" name="grade" type="text" />
          <button type="submit">Submit</button>
      </form>

      So this object has an invalid email address. So this will return Error.

      type EmailUser = {
          name: string
          email: EmailBasic
      }
      
      handleSubmit = (event: SubmitEvent) => {
          try {
              const formData = getFormData(event) as EmailUser
          } catch (ex) {
              console.error(ex)
          }
      }

      Please wrap this method with a try catch block. If there is an issue with form data validations, the event will go to catch block.
      for an example below error will be triggered on invalid email address

      Error: INVALID_EMAIL
      

      For this example, when the form is submitted, formData will be like below,

      { "name": "John", "email": "john@example.com", "grade": "A" }

      Further improvements on this method and form related improvements will be there will next versions.

1.1.1

28 Mar 10:54
30526a5

Choose a tag to compare

  • fix extract method to allow null and undefined checks
  • add unit tests
  • add unit tests to pipelines

1.1.0

19 Mar 06:43
e6dd3fc

Choose a tag to compare

Minor Feature Improvement with Email Validations

With this version now you can use email validations to validate emails inside objects and string emails

Email Validators (Available with v1.1.0)

  • validateEmail Check given email address is valid..

    • Parameters

      1. email Email Address (EmailBasic type which is coming with this package)

      Assume we have this email:

      test@test.com
      

      You can use below mentod to validate this email address

      const validateSingleEmail = validateEmail('test@test.com')
  • EmailBasic type
    from this custom basic type, you can validate basic email on development

  • getEmail Check given email address is valid.

    • Parameters

      1. email Email Address (EmailBasic type which is coming with this package)

      Assume we have this email:

      test@test.com
      

      You can use below mentod to validate this email address

      const validateSingleEmail = validateEmail('test@test.com')

      if email is valid, email will be returned. otherwise error exception will get returned.

  • validateEmailObject In Same way you can use this method which will return the entire object, if the email address is valid

    • Parameters

      1. obj Original Object
      2. path key path

      You can use below mentod to validate object email

      try {
          return validateEmailObject(userData, 'contact.email')
      } catch (ex) {
          return ex
      }

      if email is valid, email will be returned. otherwise error exception will get returned.

  • autoValidateEmail Validate an object if the object contains key which contains word 'email'

    • Parameters

      1. obj Original Object

      Lets say you have an object which needs to be validated if the object has any key value with key contains word 'email'. Then you can use this method.

      Lets say you have below mentioned object

      const userDataError: User = {
          name: 'heshan',
          contact: {
              email: 'test@#.c',
              address: 'Malmö',
          },
      }

      So this object has an invalid email address. So this will return Error.

      try {
          return autoValidateEmail(userData)
      } catch (ex) {
          return ex
      }

      if email is valid, email will be returned. otherwise error exception will get returned.

      Error: INVALID_EMAIL
      

1.0.6

18 Mar 17:21
42042a5

Choose a tag to compare

  • Added Demo Page with samples
  • Updated Readme file

1.0.5

17 Mar 12:47
88fb950

Choose a tag to compare

What's Changed

  • fix package dependencies and workflow by @heshansw in #1

Full Changelog: v1.0.2...1.0.5