Giter VIP home page Giter VIP logo

caster's Introduction

Caster

Castea un valor a diferentes tipos

Usage

    Cast::as($value, 'type')    

Type chain

     Cast::as('   -159.056     ', 'trim|abs|currency')
     //159.06

Cast

Cast::as('   -159.056     ', 'trim|abs|currency') //159.06
Cast::as('     999   ', 'spaces') //999
Cast::as('     999   ', 'trim') //999
Cast::as(['1'], 'boolean') //true
Cast::as('true', 'boolean') //true
Cast::as(' true ', 'boolean') //true
Cast::as(['3',4], 'boolean') //true
Cast::as('false', 'boolean') //false
Cast::as('other', 'boolean') //true
Cast::as('', 'boolean') //false
Cast::as('0', 'boolean') //false
Cast::as(0, 'boolean') //false
Cast::as([], 'boolean') //false
Cast::as('18-ene-2022', 'date') //Carbon\Carbon
Cast::as('15-11-1985', 'date') //Carbon\Carbon
Cast::as('2022-02-25', 'date') //Carbon\Carbon
Cast::as('2022-02', 'date') //Carbon\Carbon (year and month)
Cast::as('2022-feb', 'date') //Carbon\Carbon (year and month)
Cast::as('jun-1985', 'date') //Carbon\Carbon (year and month)
Cast::as('123.126666', 'integer') //123
Cast::as('123.126666', 'int') //123
Cast::as('123.126666', 'float') //123.126666
Cast::as('123.126666', 'double') //123.126666
Cast::as('123.126666', 'currency') //123.13
Cast::as('1578.56666', 'currency') //1578.57
Cast::as('1578.544466', 'currency') //1578.54

Manipulations

Cast::as('   123456789     ', 'trim|truncate:3') //123
Cast::as('123.126666', 'roundup:3') //123.127
Cast::as('123.126666', 'round:3') //123.127
Cast::as('1221.129316666', 'round:2') //1221.13
Cast::as('123.9999', 'floor') //123
Cast::as('123.126666', 'ceil') //124

// spread:max-words:max-items:key1,key2,key(max-items)
Cast::as('123123123', 'spread:3') //['123','123','123']
Cast::as('123123123', 'spread:3,2') //['123','123']
Cast::as('123123123', 'spread:3,2,one,two') //['one'=>'123','two'=>'123']

// spreadword:max-words:max-items:key1,key2,key(max-items)
$str = 'Lorem ipsum dolor sit amet consectetur, adipisicing elit.';
Cast::as($str, 'spreadword:4:2') //['Lorem', 'ipsum']
Cast::as($str, 'spreadword:4,2,line1,line2') //['line1' => 'Lorem', 'line2' => 'ipsum']
Cast::as($str, 'spreadword:spreadword:15') //['Lorem ipsum', 'dolor sit amet', 'consectetur,', 'adipisicing', 'elit.']

Licence

This package is open-sourced software licensed under the MIT license.

caster's People

Contributors

cmpere avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.